BBCode
Posted: Sat May 07, 2011 4:34 pm
I remember reading up and this, and I modified it to my liking and added my own codes a while back. Could be useful, although the youtube one is kind of a let down
It works, you just need the video id code. I'm sure you you can do full links if you use an explode() and substr(), I haven't got around to that yet. Anway, less of the boring stuff, more of the code:
function bbcode($text) {
$search = array(
'/\[b\](.*?)\[\/b\]/is',
'/\[i\](.*?)\[\/i\]/is',
'/\[u\](.*?)\[\/u\]/is',
'/\[img\](.*?)\[\/img\]/is',
'/\[url\](.*?)\[\/url\]/is',
'/\[url\=(.*?)\](.*?)\[\/url\]/is',
'/\[size\=(.*?)\](.*?)\[\/size\]/is',
'/\[colour=(.*?)\](.*?)\[\/colour\]/is',
'/\[center\](.*?)\[\/center\]/is',
'/\[right\](.*?)\[\/right\]/is',
'/\[left\](.*?)\[\/left\]/is',
'/\[youtube\](.*?)\[\/youtube\]/is'
);
$replace = array(
'<strong>$1</strong>',
'<em>$1</em>',
'<u>$1</u>',
'<img src="$1" />',
'<a href="$1">$1</a>',
'<a href="$1">$2</a>',
'<font size="$1">$2</font>',
'<font color="$1">$2</font>',
'<center>$1</center>',
'<div style="text-align:right;">$1</div>',
'<div style="text-align:left;">$1</div>',
'<iframe title="YouTube video player" width="640" height="390" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>'
);
$bb = preg_replace ($search, $replace, $text);
return $bb;
}