PHP similar_text() Function
Definition
The similar_text() function calculates the similarity between two strings.
Syntax
PHP similar_text() Function has the following syntax.
similar_text(string1,string2,percent)
Parameter
Parameter | Is Required | Description |
---|---|---|
string1 | Required. | First string to be compared |
string2 | Required. | Second string to be compared |
percent | Optional. | Variable name for storing the similarity in percent |
Return
PHP similar_text() Function returns the number of matching characters of two strings.
Example
Calculate the similarity between two strings and return the matching characters:
<?php
echo similar_text("Hello World","Hello from java2s.com");
?>
The code above generates the following result.
Example 2
Calculate the similarity between two strings in percent:
<?php
similar_text("Hello World","Hello from java2s.com",$percent);
echo $percent;
?>
The code above generates the following result.