How to check a partial similarity of two strings in PHP

前端 未结 5 1140
清歌不尽
清歌不尽 2020-12-08 02:51

Is it any function in PHP that check the % of similarity of two strings?

For example i have:

$string1=\"Hello how are you doing\" 
$string2= \" hi,          


        
5条回答
  •  悲哀的现实
    2020-12-08 03:41

    As other answers have already said, you can use similar_text. Here's the demonstration:

    $string1="Hello how are you doing" ;
    $string2= " hi, how are you";
    
    echo similar_text($string1, $string2, $perc); //12
    
    echo $perc; //61.538461538462
    

    will return 12, and will set in $perc the percentage of similarity as you asked for.

提交回复
热议问题