Simple PHP BBCode

, ,

Many websites allow visitors to contribute to the sites’s content through forums, blogs etc . When you’re building such sites, it’s a good idea to provide users with the ability to enhance that content by posting formatted text. Here is a simple example of how to use bbcode with php.

$text="[b]some text[b] using bbcode";

$find = array(
$replace = array(
"<span style=\"text-decoration: underline;\">\\1</span>",
"<a href=\"\\1\">\\1</a>",
"<a href=\"\\1\">\\2</a>",
"<blockquote><div style=\"font-size: 12px;\">quote (\\1):</div><div style=\"border:1px solid #ACA899;\">\\2</div></blockquote>",
"<blockquote><div style=\"font-size: 12px;\">quote:</div><div style=\"border:1px solid #ACA899;\">\\1</div></blockquote>",


Comments are closed.