Hi List,
I have worked out how to highlight all search words in a string. I hope its
useful to some one. Please make it better if you can so we can all share it.
But what I want to know is how can I treat each string with this
highlighting routine individually so that my output is each string
highlighted where necessary like the single string code dose below.
So I turn $string into an array by $string[] for each three lines and tackle
each one separately and when all search words are highlighted for that
string do the next then the next and end up with 3 strings with each word in
the string highlighted.
Sorry for such a big post but I am trying to be as clear as possible to help
others who may find this useful
Thank you for any help or code adjustments
Dave Carrera
--- Current code below ---
<?php
$string = "Hello hello server site search me and highlight my words in
search array words";
//$string = "Hello hello this is the second array elemaent to test server";
//$string = "this IS the third element of an array for words testing";
$string2 = "Hello hello server site search me and highlight my words in
search array words";
$search = "hello array words";
//$string = trim($string);
$search = trim($search);
$words = explode(' ',$search);
$words = array_unique($words);
//$mysearchstring = strchr ($string,$far[0]);
//$bold_find = substr($mysearchstring,0,$chars);
for($i=0; $i<=count($words); $i++){
$word = preg_replace("/#/","\#",$words[$i]);
$pregmatch = "#($word)(?![^<]*>)#i";
$pregreplace = "<b>$1</b>";
$h_string = preg_replace($pregmatch,$pregreplace,$string);
$string = $h_string;
}
echo "Clean: $string2<br />";
echo "Criteria: $search<br />";
echo "HighLighted: $h_string<br />";
?>
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.676 / Virus Database: 438 - Release Date: 03/05/2004
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php