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
|
|
Get Your Diploma!
W3Schools' Online Certification Program is the perfect solution for busy
professionals who need to balance work, family, and career building.
The HTML Certificate is for developers who want to document their knowledge of HTML, XHTML, and CSS.
The JavaScript Certificate is for developers who want to document their knowledge of JavaScript and the HTML DOM.
The XML Certificate is for developers who want to document their knowledge of XML, XML DOM and XSLT.
The ASP Certificate is for developers who want to document their knowledge of ASP, SQL, and ADO.
The PHP Certificate is for developers who want to document their knowledge of PHP and SQL (MySQL).
|
|