09-22-2008, 01:41 PM
|
#1 (permalink)
|
|
The Addict
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
|
str_replace??
I have this code
PHP Code:
$highlightWords = explode(" ", $searchString);
$s = sizeof($highlightWords);
for($i=0;$i<=$s;$i++) {
$info = str_replace($highlightWords[i], "<span class=\"highlight\">$highlightWords[i]</span>", $info);
}
And it does not work. However If i just do
PHP Code:
$info = str_replace($highlightWords[0], "<span class=\"highlight\">$highlightWords[0]</span>", $info);
without the loop it seems to work.
My array contains a couple words that were entered into the search bar.
What i am doing with this code is searching a string and highlighting everywhere that a searched word appears.
any ideas?
|
|
|
|