Why am I getting three arrays ? --- code ---
<?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 search"; //$string = trim($string); $search = trim($search); function searchlines(){ global $search; global $string; $words = explode(' ',$search); $words = array_unique($words); for($i=0; $i<=count($string); $i++){ $word = preg_replace("/#/","\#",$words[$i]); $pregmatch = "#($word)(?![^<]*>)#i"; $pregreplace = "<b>$1</b>"; $h_string = preg_replace($pregmatch,$pregreplace,$string); $string = $h_string; } echo $string; } array_walk($string, 'searchlines'); //echo "Clean: $string2<br />"; //echo "Criteria: $search<br />"; //echo "HighLighted: $h_string<br />"; ?> My output is 3 x the expected output. Why ? Any help is appreciated Dave Carrera -----Original Message----- From: Burhan Khalid [mailto:[EMAIL PROTECTED] Sent: 05 May 2004 11:00 To: Dave Carrera; [EMAIL PROTECTED] Subject: Re: [PHP] Walk though array applying my highlighting routine? Dave Carrera wrote: > 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. > http://www.php.net/array_walk array_walk -- Apply a user function to every member of an array --- Incoming 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 --- 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