Re: Need to mark similar phrases in two different texts



SuperNova wrote:
I need to mark similar phrases in two different texts, for example to
use <b> tag.

Why do you want this?

This may work:
1) Make a list of words in each text.
2) Compute the intersection of these lists, so that the result is a list
with words which are present in both texts.
3) Filter this list to avoid common words such as 'it' and 'a'.
4) Mark the all words in the list bold in the texts.

Something like this:

<?php
$text1 = 'Google Chrome[...]';
$text2 = 'Hematology Analyzers[...]';

// We don't want case sensitivity
$lower1 = strtolower($text1);
$lower2 = strtolower($text2);

// Array of words
$array1 = preg_split('/\W/', $lower1);
$array2 = preg_split('/\W/', $lower2);

// Intersect
$intersect = array_intersect($array1, $array2);

// Filter
$filter = array('a', '');
$filtered = array_diff($intersect , $filter);

// Make bold
foreach ($filtered as $word) {
$text1 = preg_replace("/($word)/i", '<b>\1</b>', $text1);
$text2 = preg_replace("/($word)/i", '<b>\1</b>', $text2);
}

echo $text1;
echo $text2;
?>
.