Page 1 of 1

hilight substring

Posted: Tue Oct 14, 2003 4:24 am
by yaron
Hello all,
I have this code

Code: Select all

<?php
$string='<This is my string>';
$sub="is";
$hilighted=str_replace($sub,"<font color=yellow>$sub</font>",$string);
echo htmlentities($hilighted);
?>
Because my string is between <> I can't seem to hilight the substring because I need to use htmlentities!
I need to show the <> and to prevent the browser to process it like html tag!

any ideas?

Posted: Tue Oct 14, 2003 4:30 am
by JAM
Move the htmlentities() to the beginning.

Code: Select all

<?php
$string = htmlentities('<This is my string>');
$sub="is";
$hilighted=str_replace($sub,"<font color=yellow>$sub</font>",$string);
echo $hilighted;
?>

Posted: Tue Oct 14, 2003 4:38 am
by yaron
thanks,
silly me
So simple ;-)

Posted: Tue Oct 14, 2003 8:22 am
by liljester
or you could use < and >