Jump to content

[SOLVED] Coloring certain text.


MasterACE14

Recommended Posts

you need a regex that picks out the the words and then raps a span around them with the correct color.

 

<?php
$str = 'YOUR TEXT STRING HERE WITH STUFF';

$lookfor = array (
                      '/(TEXT)|(HERE)/i',
                      '/(STRING)|(STUFF)/i'
                      );
$replace = array (
                       '<span style="color: #f00;">$1</span>' ,
                       '<span style="color: #369">$1</span>'
                       );
echo preg_replace($lookfor, $replace, $str);
?>

 

that should make 'text' and 'here' red and 'string' and 'stuff' a blue colour the i modifier shoudl make it caseinsensitive.

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.