0

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>
?>
4
Contributors
3
Replies
6
Views
7 Years
Discussion Span
Last Post by phplover
0

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

0

As cccgal jas mentioned, replace the line

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

with

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

Thanks for this :)

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

Thanks!

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.