View Single Post
Old 01-22-2007, 12:32 PM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,489
sde is on a distinguished road
"in" is not valid in a foreach statement in php. since you have 2 arrays, you can utilize php's array_intersect() function.

i haven't tested this code, but this may work for you.
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);

// set an array of words that match in both arrays
$matched_words array_intersect($search_words$words);

// loop through array if it is an array and there is more than 0 items
if (is_array($matched_words) && count($matched_words) > 0) {

    
// append $msg var in loop
    
foreach ($matched_words as $each) {
        
$msg .= "<b>".$each."</b> ";
    }

// set $msg error
} else {
    
$msg "There were no matches found.";
}

echo(
$msg);
?>
__________________
Mike
sde is offline   Reply With Quote