Re: Need to mark similar phrases in two different texts
- From: Sjoerd <sjoerder@xxxxxxxxx>
- Date: Sun, 07 Sep 2008 16:25:02 +0200
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;
?>
.
- Follow-Ups:
- Re: Need to mark similar phrases in two different texts
- From: SuperNova
- Re: Need to mark similar phrases in two different texts
- References:
- Need to mark similar phrases in two different texts
- From: SuperNova
- Need to mark similar phrases in two different texts
- Prev by Date: Re: What is wrong in my source-code?
- Next by Date: prevent php execute
- Previous by thread: Re: Need to mark similar phrases in two different texts
- Next by thread: Re: Need to mark similar phrases in two different texts
- Index(es):
Relevant Pages
|