RShadow Posted July 23, 2006 Share Posted July 23, 2006 I'm attempting to build a parser similar to bbcode style, and I'm not exactly sure how to approach this... all the methods I can think up in my head would require basicly a character by character analayis that would be .. well pretty complex.. I'm sure there is a better way in PHP. Doing something like smilies is realativly simple.. pretty much a simple search and replace.. however I'm not exactly sure how I would go about searching for a match pair such as [ some tag ] [ /some end tag ] Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 23, 2006 Share Posted July 23, 2006 Heres a simple BBCode parser:[code]<?phpfunction bbcode($txt){ // bbcodes $bbcodes = array( "|\[b\](.+)\[/b\]|is", "|\[u\](.+)\[/u\]|is", "|\[i\](.+)\[/i\]|is" ); // html $replace = array( "<strong>$1</strong>", "<u>$1</u>", "<em>$1</em>" ); $txt = preg_replace($bbcodes, $replace, $txt); return nl2br($txt);}$str = "[b]hey[/b] a [u][i]BBCode parser[/i][/u]! ";$str = bbcode($str);echo $str;?>[/code]converts any text surrounded in b, i and u tags into bold, italics and underline text.For a emoticon parser, [url=http://ryanslife.net/2006/07/12/php-simple-emoticon-support/]heres a tutorial[/url] 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.