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
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.
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
Thanks for this :)
I was looking for an already made simple bbcode function. Will put this to good use.
Thanks!
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.