PHP BBCode Parser

BB code is a very simple set of instructions (also known as BB tags) that provide rules as to how a piece of text should be formatted. When a page that contains BB code is displayed in the browser, the BB tags are replaced with appropriate HTML tags that the browser can understand.

cdl_capture_2012-01-03-49_ 000

function BBCode ($string) {
    $search = array(
    $replace = array(
        \'<img src="\\1">\',
        \'<a href="\\1">\\2</a>\',
    return preg_replace($search, $replace, $string);


echo BBCode(\'Here is some [b]Bold![/b] and so on!\');


Leave a comment