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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted June 22, 2007 Author Share Posted June 22, 2007 Excellant! Thanks heaps! Regards ACE Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.