Jump to content

bbcode on forum


runnerjp

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.