BB Parser ~ PHP

Status
Not open for further replies.

Waffle

Alpha Geek
Ok I've developed a BB system similar to the one here, and many other sites, to allow bold etc to be used on forms etc etc.

My code:

PHP:
<?php
function bbcode($string){
$r = array(
"[b]" => "<b>",      // bold
"[/b]" => "</b>",  
"[i]" => "<i>",        //italic
"[/i]" => "</i>", 
"[u]" => "<u>",    //underline
"[/u]" => "</u>",
"[br]" => "<br>",   //break
);
$string = str_replace(array_keys($r), array_values($r), $string);

echo $string;
}
?>
And I'd like to have more..ideally the following, but I have no idea how to code them.

PHP:
<?
[url]www.site.com]Link Name[/url] //I tried this, but it never worked properly. Also, the "Link Name" would have to be optional, in case it is missed out in user input - dont want any errors.

[url=www.site.com]Site[/url] would also be acceptable.

[img][/img]
[font color=red][/font]

?>
suggestions?

thanks.
 
Status
Not open for further replies.
Back
Top