runnerjp Posted May 30, 2008 Share Posted May 30, 2008 im trying to add bbocde to my forum.. so i have tried doing this to test things out before i add it to my forum but its not working <?php function bbcode ($string) { // All the default bbcode arrays. $bbcode = array( //Text Apperence '#\[b\](.*?)\[/b\]#si' => '<b>\\1</b>', '#\[i\](.*?)\[/i\]#si' => '<i>\\1</i>', '#\[u\](.*?)\[/u\]#si' => '<u>\\1</u>', '#\[s\](.*?)\[/s\]#si' => '<strike>\\1</strike>', //Font Color '#\[color=(.*?)\](.*?)\[/color\]#si' => '<font color="\\1">\\2</font>', //Text Effects '#\[bl\](.*?)\[/bl\]#si' => '<blink>\\1</blink>', '#\[marquee\](.*?)\[/marquee\]#si' => '<marquee>\\1</marquee>', //Other '#\[code\](.*?)\[/ code]#si' => '<div class="bbcode_code_title">CODE:</div><div class="bbcode_code_code">\\1<div>', '#\[url=http://(.*?)\](.*?)\[/url]#si' => '<a href="\\1" target="_blank">\\2</a>', '#\[quote\](.*?)\[/quote\]#si' => '<div class="bbcode_quote_title">CODE:</div><div class="bbcode_quote_quote">\\1<div>', '#\[img\](.*?)\[/img\]#si' => '<img src="\\1">', '#\[email\](.*?)\[/email\]#si' => '<a href="mailto:\\1">\\1</a>' ); $output = preg_replace(array_keys($bbcode), array_values($bbcode), $string); return $output; } ?> <?php bbcode('stuff here [b]bold text[/b]'); ?> i just get a blank page/// Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 30, 2008 Share Posted May 30, 2008 Yeah. You just didn't echo it: echo bbcode('stuff here [b]bold text[/b]'); Quote Link to comment Share on other sites More sharing options...
runnerjp Posted May 30, 2008 Author Share Posted May 30, 2008 ahh yes that worked... ok so if i wanted to add it to this $message=nl2br($message); how would i do it? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 30, 2008 Share Posted May 30, 2008 Change this: return $output; To: return nl2br($output); Quote Link to comment Share on other sites More sharing options...
runnerjp Posted May 30, 2008 Author Share Posted May 30, 2008 that didnt work sadly... better explain a little... ok so i have functions.php where function bbcode ($string) { // All the default bbcode arrays. $bbcode = array( //Text Apperence '#\[b\](.*?)\[/b\]#si' => '<b>\\1</b>', '#\[i\](.*?)\[/i\]#si' => '<i>\\1</i>', '#\[u\](.*?)\[/u\]#si' => '<u>\\1</u>', '#\[s\](.*?)\[/s\]#si' => '<strike>\\1</strike>', //Font Color '#\[color=(.*?)\](.*?)\[/color\]#si' => '<font color="\\1">\\2</font>', //Text Effects '#\[bl\](.*?)\[/bl\]#si' => '<blink>\\1</blink>', '#\[marquee\](.*?)\[/marquee\]#si' => '<marquee>\\1</marquee>', //Other '#\[code\](.*?)\[/ code]#si' => '<div class="bbcode_code_title">CODE:</div><div class="bbcode_code_code">\\1<div>', '#\[url=http://(.*?)\](.*?)\[/url]#si' => '<a href="\\1" target="_blank">\\2</a>', '#\[quote\](.*?)\[/quote\]#si' => '<div class="bbcode_quote_title">CODE:</div><div class="bbcode_quote_quote">\\1<div>', '#\[img\](.*?)\[/img\]#si' => '<img src="\\1">', '#\[email\](.*?)\[/email\]#si' => '<a href="mailto:\\1">\\1</a>' ); $output = preg_replace(array_keys($bbcode), array_values($bbcode), $string); return nl2br($output); } is stored. i have called functions.php up in my script and i have added into my db a tester of hey how to call up my messages i use this <table class='maintable'> <tr class='headline'><td width=20%>Author</td><td width=80%>Post</td></tr> <? if ($pagenum == 1){ ?> <tr class='mainrow'><td valign='top'><? echo $gettopic3[author] ?> </td> <td vakign='top'>created on <? echo $gettopic3[showtime]?><br> <hr> <p> <? $message=strip_tags($gettopic3['post']); $message=nl2br($message); ?> <? echo $message ?></p> <p><br> </p></td></tr><? } $getreplies="Select * from forumtutorial_posts where parentid='$id' $max"; //getting replies $getreplies2=mysql_query($getreplies) or die("Could not get replies"); while($getreplies3=mysql_fetch_array($getreplies2)) { ?> so how can i make it so my £message displays my function bbcode Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 30, 2008 Share Posted May 30, 2008 Replace this bit: $message=nl2br($message); With: $message=bbcode($message); 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.