I am trying to compare two strings in PHP. But I don't know why it is not working.
<?php
$string1="what is the highest peak in the world";
$string2="The highest peak of World is";
$find_ans=1;
compare_string($string1,$string2,$find_ans);
function compare_string($str1,$str2,$find_ans)
{
$str1=strtolower($str1);
$str2=strtolower($str2);
$skip_word="a,an,the,what,when,where,who,whom,which,whose,why,how,are,am,is,was,were,has,have,had";
$word_arr=explode(",",$skip_word);
$new_str1=str_replace($word_arr,'',$str1);
$new_str2=str_replace($word_arr,'',$str2);
echo $new_str1.'<br/>';
echo $new_str2.'<br/>';
$sim = similar_text($new_str1, $new_str2, $perc);
echo $perc.'<br/>';
}
?>
The similar_text returned 70.769230769231 if I use resort, but it returned 83.333333333333 if I removed rsort. Here str_replace is not working.$new_str1 and $new_str2 print the same result as before.
UPDATE
I want to get results from $string1 and $string2 as "highest peak world" after doing str_replace.
But the problem is that if I change the strings as
$string1="what is the highest peak in india";
$string2="The highest peak of india is";
Then the result is "highest peak dia" But not "highest peak India".
It was my mistake: $new_str1 and $new_str2 print the same result as before.