How to use similar text in PHP
In this article I will explain how the similar_text () function can be used in PHP.
similar_text() function in PHP
- The similar_text() function is used to return the number of matching characters between two strings.
- The similar_text() function can also calculate the similarity of the two strings in percent.
- The similar_text() function is slower than the levenshtein() function.
- The similar_text() function will give you a more accurate result with less modifications needed.
Syntax
similar_text(string1,string2,percent) |
Parameter
- string1 string1 is required parameter. it is specify the first string to be compared.
- string2 string2 is required parameter. it is specify the second string to be compared.
- percent percent is optional parameter. it is specify a variable name for storing the similarity in percent.
Example
The following example show to how the similar_text() function can be used in PHP.
<html>
<body>
<h3 style="color: blueviolet;">similar_text() function example in PHP</h3>
<?php
echo "First compare strings is : 'Welcome to C-sharpcorner user'".'<br>';
echo "Second compare strings is : 'Have a nice day C-sharpcorner user'".'<br/>';
echo 'No of similar characters : '.similar_text('Welcome to C-sharpcorner user', 'Have a nice day C-
sharpcorner user').'<br>';
similar_text('Welcome to C-sharpcorner user', 'Have a nice day C-sharpcorner user', $similar_percent);
echo 'Similarity between two strings in percentage : '. $similar_percent;
?>
</body>
</html>
|
Output
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here