X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

PHP similar_text() Function

PHP String Reference PHP String Reference

Example

Calculate the similarity between two strings and return the matching characters:

<?php
echo similar_text("Hello World","Hello Peter");
?>

Run example »

Definition and Usage

The similar_text() function calculates the similarity between two strings.

It can also calculate the similarity of the two strings in percent.

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.


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

Technical Details

Return Value: Returns the number of matching characters of two strings
PHP Version: 4+


More Examples

Example 1

Calculate the similarity between two strings in percent:

<?php
similar_text("Hello World","Hello Peter",$percent);
echo $percent;
?>

Run example »


PHP String Reference PHP String Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook