954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Very simple bbcode

0
By Denis Sellu on Aug 9th, 2010 8:49 pm

This is a very simple bbcode example to use on a forum or your pages. Add this to a function page and make sure the function is required on the page you want to on.

ENJOY!! :D

<?php
  function bbcode($data)
  {
          $input = array(
                  '/\[b\](.*?)\[\/b\]/is',
                  '/\[i\](.*?)\[\/i\]/is',
                  '/\[u\](.*?)\[\/u\]/is',
                  '/\[img\](.*?)\[\/img\]/is',
                  '/\[url\](.*?)\[\/url\]/is',
                  '/\[url\=(.*?)\](.*?)\[\/url\]/is'
                  );

          $output = array(
                  '<strong>$1</strong>',
                  '<em>$1</em>',
                  '<u>$1</u>',
                  '<img src="$1" />',
                  '<a href="$1">$1</a>',
                  '<a href="$1">$2</a>'
                  );

          $rtrn = preg_replace ($input, $output, $data);

          return $rtrn;
  }
$bcode = $bbcode('[i]this is testing text[/i]');// This is how you use it on a forum or a page

echo $bcode;//output: <strong>this is again another test text</strong>
?>

On line 26, I don't think you are supposed to have a $ when calling the bbcode() function.

cscgal
The Queen of DaniWeb
Administrator
19,427 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
 

As cccgal jas mentioned, replace the line

$bcode = $bbcode('<em>this is testing text</em>');// This is how you use it on a forum or a page


with

$bcode = bbcode('<em>this is testing text</em>');// This is how you use it on a forum or a page
tax14
Newbie Poster
1 post since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

Thanks for this :)

I was looking for an already made simple bbcode function. Will put this to good use.

Thanks!

phplover
Junior Poster in Training
97 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: