PHP similar_text() Function
Complete PHP String Reference
Definition and Usage
The similar_text() function returns the number of matching characters of two
strings.
It can also calculate the similarity of the two strings in percent.
Syntax
|
similar_text(string1,string2,percent)
|
| Parameter |
Description |
| string1 |
Required. Specifies the first string to be compared |
| string2 |
Required. Specifies the second string to be compared |
| percent |
Optional. Specifies a variable name for storing the
similarity in percent |
Tips and Notes
Note: The levenshtein() function is faster than the similar_text()
function. However, the similar_text() function will give you a more accurate
result with less modifications needed.
Example 1
<?php
echo similar_text("Hello World","Hello Peter");
?>
|
The output of the code above will be:
Example 2
<?php
similar_text("Hello World","Hello Peter",$percent);
echo $percent;
?>
|
The output of the code above will be:
Complete PHP String Reference
 |
W3Schools' Online Certification Program
The perfect solution for professionals who need to balance work, family, and career building.
More than 4000 certificates already issued!
|
The HTML Certificate documents your knowledge of HTML, XHTML, and CSS.
The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
|