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/// Link to comment https://forums.phpfreaks.com/topic/107984-bbcode-on-forum/ 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]'); Link to comment https://forums.phpfreaks.com/topic/107984-bbcode-on-forum/#findComment-553449 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? Link to comment https://forums.phpfreaks.com/topic/107984-bbcode-on-forum/#findComment-553456 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); Link to comment https://forums.phpfreaks.com/topic/107984-bbcode-on-forum/#findComment-553467 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 Link to comment https://forums.phpfreaks.com/topic/107984-bbcode-on-forum/#findComment-553480 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); Link to comment https://forums.phpfreaks.com/topic/107984-bbcode-on-forum/#findComment-553531 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.