highlight words
hi I have this script and it is working very good:
<?php
/****************************************
Highlighting Function
****************************************/
function highlight_words( $text, $keywords )
{
foreach( $keywords as $word )
{
$text = preg_replace( "/$word/i", '<span style="color:red;font-weight:bold;">' . $word . '</span>', $text );
}
return( $text );
}
/****************************************
Text String
****************************************/
$text = 'The big red fox jumped over the fence.<br>
Kijk maar hier heb je een enter';
/****************************************
Array Of Keywords
****************************************/
$keywords[] = $keyW;
/****************************************
Do It
****************************************/
echo( highlight_words( $text, $keywords ) );
echo "<a href='highlight.php?keyW=enter'>enter</a></p>";
echo "<a href='highlight.php?keyW=kijk'>kijk</a></p>";
?>
There is a text and when You click the links the words you clicked on will be highlighted. This is great but I want it to remmeber where you clicked on so when you click “enter” enter gets highlighted and when you click on “kijk” after that both words will be highlighted. How can I do this…ow and How can I make the text HTML so that you can put <BR> in the text?? I did it but it doesn’t work the first time befor you click.
thanks in advance zeb