Jump to content

BB code


kev wood

Recommended Posts

 

If you'd tested this function, you'd found out that you forgot to escape every single square bracket. It's an easy fix though. I also think you'll need to use the lazy (.*?) instead of (.*), to make it function with nested tags. I've used this before:

 

<?php
function bb2html($text) {
$find = array(
	'~\[b\](.*?)\[/b\]~s',
	'~\[i\](.*?)\[/i\]~s',
	'~\[u\](.*?)\[/u\]~s',
	'~\[size=(.*?)\](.*?)\[/size\]~s',
	'~\[color=(.*?)\](.*?)\[/color\]~s',
	'~\[highlight=(.*?)\](.*?)\[/highlight\]~s',
	'~\[code\](.*?)\[/code\]~s'
);
$replace = array(
	'<strong>$1</strong>',
	'<em>$1</em>',
	'<span style="text-decoration: underline;">$1</span>',
	'<span style="font-size: $1em;">$2</span>',
	'<span style="color: $1;">$2</span>',
	'<span style="background-color: $1;">$2</span>',
	'<pre>$1</pre>'
);
return preg_replace($find, $replace, $text);
}
?>

Link to comment
https://forums.phpfreaks.com/topic/110736-bb-code/#findComment-568117
Share on other sites

Here's part of mine...

$base = "http://www.a.b.com/icon/";
$pattern = array(
				'/\[b\](.+?)\[\/b\]/is',
				'/\[i\](.+?)\[\/i\]/is',
				'/\[u\](.+?)\[\/u\]/is',
				'/\[h1\](.+?)\[\/h1\]/is',
				'/\[h2\](.+?)\[\/h2\]/is',
				'/\[h3\](.+?)\[\/h3\]/is',
				'/\[h4\](.+?)\[\/h4\]/is',
				'/\[sub\](.+?)\[\/sub\]/is',
				'/\[sup\](.+?)\[\/sup\]/is',
				'/\[tt\](.+?)\[\/tt\]/is',
				'/\[s\](.+?)\[\/s\]/is',					
				'/\[em\](.+?)\[\/em\]/is',
				'/\[strong\](.+?)\[\/strong\]/is',
				'/\[samp\](.+?)\[\/samp\]/is',
				'/\[kbd\](.+?)\[\/kbd\]/is',
				'/\[code\](.+?)\[\/code\]/is',
				'/\[code=(.+?)\]

[/code]

Link to comment
https://forums.phpfreaks.com/topic/110736-bb-code/#findComment-568129
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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