PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I want to compare two articles for duplicate content and highlight these words in yellow in the output of each article. The problem I am having is to compare only 3 or more word combos and ignore 1 or 2 word combos. I think I looked at every page on php.net and did every google search known to man. I am new to php and would greatly appreciate any guidance or help.
// identify 3+, 4+, 5+, etc. consecutive matching words between 2 strings
// ignore 1 & 2 consecutive matching words between 2 strings
// string#1 = the brown dog barked all day
// string#2 = the brown dog slept all day
// 'the brown dog' = 3 consecutive matching words between the 2 strings
// 'all day' = only 2 consecutive matching words between the 2 strings
// echo both strings with dulicate 3+, 4+, 5+, etc. words highlighted in yellow
// get user input
$str1 = $_POST['text1'];
$str2 = $_POST['text2'];
// explode strings into seperate words
$str1array = explode(" ", $str1);
$str2array = explode(" ", $str2);
// compare two arrays for duplicate 3+, 4+, 5+, etc. consecutive matching words
$dupwords = array_intersect($str1array, $str2array);
// echo both articles and their word count
echo '<br /><b>Article #1</b> - ';
echo count_words($str1);
echo ' words<br />';
echo stripslashes($str1);
echo '<br /><br /><br /><b>Article #2</b> - ';
echo count_words($str2);
echo ' words<br />';
echo stripslashes($str2);
echo '<br /><br /><br /><br />';
I appreciate the help. Is there any way to adjust the code to only count 3 duplicate words or more in a row between the two strings?
In the above output it should only show array 'the brown dog' and ignore the rest as they are not 3 words in a row.