similar_text() function calculates the similarity between two strings with values and percentage.
Note: The levenshtein() function is faster than the similar_text() function. However, the similar_text() function will give you a more accurate result.
[table caption=”” width=”100%” colwidth=”15%|15%|15%|55%” colalign=”left|left|left|left”]
Name, Required /Optional, Value Type, Description
string1, Required, String, first string to be compared.
string2, Required, String, second string to be compared.
percentage, Optional, Float, Variable name to store the similarity in percent
[/table]
Note : Swapping the first and second may yield a different result.
Returns the number of matching chars in both strings.
The number of matching characters is calculated by finding the longest first common substring, and then doing this for the prefixes and the suffixes, recursively. The lengths of all found common substrings are added.
<?php echo "Similarity : ".similar_text("Hello all","Hello dear",$percent); echo "\nSimilarity percentage : ".$percent; ?>
See below is the output of above code in web browser.
Similarity : 7
Similarity percentage : 73.684210526316
<?php echo "Similarity : ".similar_text("Hello all","Hello dear"); ?>
See below is the output of above code in Web browser.
When it comes to children, there’s one universal truth: the right toy can spark imagination, build skills, and make memories…
In today’s digital age, where screens and gadgets dominate our children’s lives, there’s something heartwarming about a well-loved plush toy…
In a world dominated by screens and fast-paced routines, it’s easy to forget the simple magic of a toy in…
In the heart of Delhi’s vibrant streets lies a world where imagination meets innovation — the magical universe of toys.…
When was the last time a toy truly amazed you—not just as a product, but as a thoughtful tool for…
In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…