Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php count matching words in two strings

$string1 = 'The dog and cat love each other';
$string2 = 'the dog pooped in the yard';
$arr1 = explode(" ",$string1 );
$arr2 = explode(" ",$string2 );
$result = array_intersect($arr1 , $arr2 ); //matched elements
$num = count($result); //number of matches
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #php #count #matching #words #strings
ADD COMMENT
Topic
Name
6+1 =