View Full Version : highlight a word in php

07-18-2008, 03:24 AM
I want to highlight a word if for e,g i have apples in the description.

How can i do that in php

07-18-2008, 04:52 AM
Specify .highlight { background: yellow; } in CSS, then you may do the following:

$text = str_replace( 'apples', '<span class="highlight">apples</span>', $text );

Look into the use of arrays, and maybe even preg_replace(), to expand upon this example.