Current Location: Home> Function Categories> similar_text

similar_text

Calculate the similarity between two strings
Name:similar_text
Category:String
Programming Language:php
One-line Description:Calculate the similarity of two strings.

Definition and usage

similar_text() function calculates the similarity between two strings.

This function can also calculate the percentage similarity of two strings.

Note: levenshtein() function is faster than similar_text() function. However, the similar_text() function provides more precise results with fewer required modifications.

Example

Example 1

Calculate the similarity of two strings and return the number of matching characters:

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

Try it yourself

Example 2

Calculate the percentage similarity between two strings:

 <?php
similar_text ( "Hello World" , "Hello Shanghai" , $percent ) ;
echo $percent . "%" ;
?>

Try it yourself

grammar

 Similar_text ( string1 , string2 , percent )
parameter describe
string1 Required. Specifies the first string to be compared.
string2 Required. Specifies the second string to be compared.
percent Optional. The name of the variable that specifies the percentage similarity for storage.
Similar Functions
  • Escape metacharacter set quotemeta

    quotemeta

    Escapemetacharacters
  • Set the first character of the string to uppercase ucfirst

    ucfirst

    Setthefirstcharacter
  • Convert the first byte of the string to a value between 0-255 ord

    ord

    Convertthefirstbyteo
  • Convert the value of a one-dimensional array into a string implode

    implode

    Convertthevalueofaon
  • Reverse a string strrev

    strrev

    Reverseastring
  • Use another string to fill a string to a length str_pad

    str_pad

    Useanotherstringtofi
  • Convert logical-Hebrew to visual-Hebrew and convert newlines hebrevc

    hebrevc

    Convertlogical-Hebre
  • Calculate the edit distance between two strings levenshtein

    levenshtein

    Calculatetheeditdist
Popular Articles