View Single Post
Old 01-22-2007, 10:18 PM   #5 (permalink)
markster
Code Monkey
 
markster's Avatar
 
Join Date: Jun 2006
Posts: 65
markster is on a distinguished road
how can this script be addapted to display the entire string in order and highlight the matches? right not im using the below script but it echos something like this:

i i i i need need need need to to to to have have have have all all all all the the the the words words words words in in in in this this this this string string string string highlighted highlighted highlighted highlighted if if if if they they they they are are are are from from from from the the the the array array array array above above above above

PHP Code:
<?php 
$input 
"words to be highlighted";
$words explode(" ",$input);
$string "i need to have all the words in this string highlighted if they are from the array above";
$search_words explode(" ",$string);
foreach (
$search_words as $word_match) {
    foreach (
$words as $word_string) {
        if (
$word_string==$word_match) {
            
$msg .= "<b>$word_match<b> ";
        } else {
            
$msg .= "$word_match ";
        }
    }
}
echo(
$msg);
?>
markster is offline   Reply With Quote