identify 3 or more consecutive matching words between 2 strings

Hi,

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.

Thanks in advance,

Gary

[php]// 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 '
Article #1 - ‘;
echo count_words($str1);
echo ’ words
’;
echo stripslashes($str1);
echo '


Article #2 - ‘;
echo count_words($str2);
echo ’ words
’;
echo stripslashes($str2);
echo ‘



’;[/php]

Not sure if you are looking for this, but, here is an open source utility that does this:
http://winmerge.org/ Not sure how you get the source for it, but, worth a look.

Here’s another one…
http://www.phpclasses.org/package/2365-PHP-Compare-two-text-files-and-show-different-lines.html

Not a direct answer, but, hope it helps…

Thanks for the fast response ErnieAlex,

Winmerge is an excellent desktop application and thanks for the php class link. I am new to php so the code is still dificult for me to figure out.

I think I put too many questions/steps in this post… i’m going to break it down and ask one item at a time in the future.

Sounds good. Seems like few people are doing this and it can get tricky to do this in an internet app on a webpage. But, perhaps you can figure it out with a little help… Ask away…

Sponsor our Newsletter | Privacy Policy | Terms of Service