I have two strings such as:
$string1 = 'Hi how are you today';
$string2 = 'how' AND 'today';
$string1 could be anything as it gets it's content through a loop.
I want to be able to count how many times the two words in $string2 appear in $string1. Both words have to exist, in any order.
This is what I have so far. But it only checks if "text" exists. How can I change it to check if "text" and "text2" exist in any order.
$sitesToCheck = array("http://mysitecom.com", "http://mysitetwocom.com"));
foreach ($sitesToCheck as $site) {
$html = file_get_html($site);
foreach ( $html->find('.table tr td.span8') as $element ) {
$list .= $element->plaintext;
$item_count = count(explode('text', $list));
}
}
Thanks,
Here is one way to do it. You can use PHP's array_intersect
$string1 = 'Hi how are you today';
$string2 = 'how today';
$arr1 = explode(" ",$string1 );
$arr2 = explode(" ",$string2 );
$result = array_intersect($arr1 , $arr2 ); //matched elements
$num = count($result); //number of matches