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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.