function extractWords($s) {
$stopWords = array('i', 'me', 'my', 'myself', 'we', 'our', 'ours', 'ourselves', 'you',
'your', 'yours', 'yourself', 'yourselves', 'he', 'him', 'his', 'himself', 'she', 'her',
'hers', 'herself', 'it', 'its', 'itself', 'they', 'them', 'their', 'theirs', 'themselves',
'what', 'which', 'who', 'whom', 'this', 'that', 'these', 'those', 'am', 'is', 'are', 'was',
'were', 'be', 'been', 'being', 'have', 'has', 'had', 'having', 'do', 'does', 'did', 'doing',
'a', 'an', 'the', 'and', 'but', 'if', 'or', 'because', 'as', 'until', 'while', 'of', 'at',
'by', 'for', 'with', 'about', 'against', 'between', 'into', 'through', 'during', 'before',
'after', 'above', 'below', 'to', 'from', 'up', 'down', 'in', 'out', 'on', 'off', 'over',
'under', 'again', 'further', 'then', 'once', 'here', 'there', 'when', 'where', 'why',
'how', 'all', 'any', 'both', 'each', 'few', 'more', 'most', 'other', 'some', 'such', 'no',
'nor', 'not', 'only', 'own', 'same', 'so', 'than', 'too', 'very', 's', 't', 'can',
'will', 'just', 'don', 'should', 'now', 'means');
$s = strtolower($s);
$s = trim($s);
// remove all chars except a-zA-Z
$s = preg_replace('/[^a-zA-Z]/', ' ', $s);
// Remove multiple whitespace
$s = preg_replace('/\s\s+/i', ' ', $s);
preg_match_all('/\b.*?\b/i', $s, $words);
$words = $words[0];
// Get only words that are not stop words with length > 2
foreach ($words as $key=>$val) {
if ($val == '' || in_array(strtolower($val), $stopWords) || strlen($val) <= 2) {
unset($words[$key]);
}
}
// Remove duplicate words and count word occurrences
$thewords = array();
if (is_array($words)) {
foreach ($words as $key => $val) {
if (isset($thewords[$val]) ) {
$thewords[$val]++;
} else {
$thewords[$val] = 1;
}
}
}
arsort($thewords);
return $thewords;
}
$s1 = "What It Means to Be a Microsoft Certified partner?" . " arr1";
$s2 = "A Microsoft Gold-Certified partner is a company that
has agreed to collaborate and establish a close working
relationship with Microsoft. Having that title means
the company who applied itself has earned the highest
standards of Microsoft's widely-recognized partnership program." . " array2";
$words = extractWords($s1);
$s = implode(', ', array_keys($words));
$array1 = explode(" ", $s);
$words = extractWords($s2);
$s = implode(', ', array_keys($words));
$array2 = explode(" ", $s);
$result = array_intersect($array1, $array2);
print_r($result);
/*
run:
Array
(
[0] => microsoft,
[1] => certified,
[2] => partner,
)
*/