> And what about highlighting the whole word which contains the searched term.
yes - like i said - this would be a solution:
>> - or: displays entries that contain "bytes" and highlights "bytes"
do you have any idea how to manage it?
best wishes
philipp
www.ipdraw.org
am 21.06.2003 12:57 Uhr schrieb Milan Reznicek unter [EMAIL PROTECTED]:
> And what about highlighting the whole word which contains the searched term.
>
>
> ----- Original Message -----
> From: <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Saturday, June 21, 2003 12:31 PM
> Subject: [PHP] search-and-highlight issue ("byt tes")
>
>
>> hello!
>>
>> i have a problem with a search-and-highlight script (see code below):
>>
>> a search for "byt tes" matches entries that contain "bytes" but only
>> highlights "byt"*.
>>
>> *) because after the first search term ("byt") is found the line is
> modified
>> into <span class="highlight">byt</span>es and therefore the secound search
>> term ("tes") can't be highlighted anymore.
>>
>>
>> 1. general question
>>
>> i'm not quite sure if a search like this should match entries that contain
> a
>> combination of both terms ("bytes").
>> of course, the word "bytes" contains both search terms - but on the other
>> hand, a search for "byt tes" indicates that i'm looking for TWO terms (and
>> also for TWO "t"s).
>>
>>
>> 2. how to do it anyway?
>>
>> do you have an idea how to accomplish that this kind of search
>> - either: does NOT display entries that match "bytes"
>> - or: displays entries that contain "bytes" and highlights "bytes"
>>
>> (because both solutions seem to be somehow logical it may depend on the
>> easiness of creation and/or the speed of processing.)
>>
>>
>> thanks a lot for your effort!!
>>
>> best wishes
>>
>> philipp
>> www.ipdraw.org
>>
>>
>> ---
>> code
>>
>> notes:
>> - the highlight/preg_replace part is built to skip html tags.
>> - if you have any other suggestions for improvements, please let me know.
>>
>>
>> if (isset($src)) {
>>
>> if (preg_match("/[A-z]/", $src) | preg_match("/[0-9]/", $src)) {
>>
>> $src = stripslashes($src);
>> $src = preg_replace("/\,/i", " ", $src);
>> $src = html_entity_decode($src);
>> $src = preg_replace("/ /i", " ", $src);
>> $src = preg_replace("/[[:space:]]+/i", " ", $src);
>> $src = trim($src);
>>
>> $handle = fopen($entries, "r");
>> $i = 1;
>> $results = 0;
>>
>> while ($i <= $dbs_total) {
>> $buffer = fgets($handle, 4096);
>> $buffer_raw = strip_tags($buffer);
>> $buffer_raw = preg_replace("/ /i", " ", $buffer_raw);
>>
>> $words = explode(' ', $src);
>> $t = 0;
>> $test='return(';
>> foreach($words as $word)
>> {
>> if($t>0)$test.=' && ';
>> $test.='strstr($buffer_raw,\''.$word.'\')';
>> $t++;
>> }
>> $test.=');';
>> // 01:A
>> if (eval($test)) {
>> foreach($words as $word)
>> {
>> $wordreg = preg_replace('/([\.\*\+\(\)\[\]])/','\\\\\1',$word);
>> $buffer =
>>
> preg_replace('/(<)([^>]*)('.("$wordreg").')([^<]*)(>)/sei',"'\\1'.preg_repla
>>
> ce('/'.(\"$wordreg\").'/i','###','\\2\\3\\4').'\\5'",stripslashes($buffer));
>> $buffer = preg_replace('/('.$wordreg.')/si','<span
>> class="highlight">\\1</span>',stripslashes($buffer));
>> $buffer = preg_replace('/###/si',$word,$buffer);
>> }
>> echo $buffer;
>> $results++;
>> }
>> $i++;
>> }
>> fclose ($handle);
>> } else {
>> $illegal_src = 1;
>> }
>> }
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php