Jump to content

[SOLVED] PHP 'pre-assigned' highlighting..?


DamienRoche

Recommended Posts

Hi guys. I've just been looking into Geshi and how it functions..it's way too complicated for me right now but I have a question.

 

Is there a simple way I can target every instance of a word in a string and style it?

 

Any input much appreciated. Thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/126495-solved-php-pre-assigned-highlighting/
Share on other sites

<?php
$string = "There are some words in here, and I just so happen to like words.  Isn't that great?  I don't like it when words are inotherwords though. Aww.";
$new_str = preg_replace('/\bwords\b/', '<span class="highlight">$0</span>', $string);
echo $new_str;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.