Forum Moderators: coopster

Message Too Old, No Replies

Highlighting specific words

heightlight, words

         

scriptmasterdel

12:06 pm on Mar 23, 2006 (gmt 0)

10+ Year Member



Hi All,
Im just wondering if anyone could enlighten me on how this method is done? With or without intergrating a mysql datebase of keywords.

I always thought the ereg_replace function could do it but i haven't figured out how to pass the selected keywords from a mysql database.

To sum it up.
How do you "heightlight" keywords taken from a database or a variable.

$var = "This is the ultimate keyword";

now if i wanted the word "ultimate" to be hightlighted, what would i do?

... Also i would like to know how to do this with multiple words.

If there is a simple function for this, or a previous thread about this, then pleas let me know.

Thanks for listening

omoutop

12:51 pm on Mar 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



if i understand your question correclty u ask for something like this:

$var_original = "This is the ultimate keyword";
$var_hlight = "<span style=\"background-color:#FFCC00; color:#0000FF; font-weight:bold;\">".$keyword."</span>";
$keyword = "ultimate";
$new_var = str_replace($keyword, $var_hlight, $var_original);

scriptmasterdel

1:06 pm on Mar 23, 2006 (gmt 0)

10+ Year Member



Your a star, thank you. I just needed someone to start me off and that is exactly what you did.

Thanks again, Much Appreciated

[***EDIT***]

the var $keyword needs to go a line before the $var_hlight (for any others that might use this code)

Cheers,
Del

coopster

4:34 pm on Mar 23, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, scriptmasterdel :)