MasterACE14 Posted June 22, 2007 Share Posted June 22, 2007 I want to echo some text from my database, and color code different words, similar to how the code tags in this forum work. how do I color text and phrases? Regards ACE Link to comment https://forums.phpfreaks.com/topic/56686-solved-coloring-certain-text/ Share on other sites More sharing options...
Orio Posted June 22, 2007 Share Posted June 22, 2007 You mean bbcode? You need to give out some more information or examples... Orio. Link to comment https://forums.phpfreaks.com/topic/56686-solved-coloring-certain-text/#findComment-279997 Share on other sites More sharing options...
MasterACE14 Posted June 22, 2007 Author Share Posted June 22, 2007 nah not bbcode, maybe write a function that adds HTMl color codes to certain words or something. Regards ACE Link to comment https://forums.phpfreaks.com/topic/56686-solved-coloring-certain-text/#findComment-280005 Share on other sites More sharing options...
ToonMariner Posted June 22, 2007 Share Posted June 22, 2007 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. Link to comment https://forums.phpfreaks.com/topic/56686-solved-coloring-certain-text/#findComment-280016 Share on other sites More sharing options...
MasterACE14 Posted June 22, 2007 Author Share Posted June 22, 2007 Excellant! Thanks heaps! Regards ACE Link to comment https://forums.phpfreaks.com/topic/56686-solved-coloring-certain-text/#findComment-280075 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.