Forum Moderators: coopster
It's very similar so I figured that you'd be able to get a solution from it, but here's a more specific example:
$string = "[color=880000]fish sticks[/color] are cool!";
$pattern = "/\[color=([0-9]{6})\](.*)\[\/color\]/is";
$replace = "<span style='color: \\1'>\\2</span>";
echo preg_replace($pattern,$replace,$string);
Good luck and merry christmas :)
$replace = "<span style='color: [b]#[/b]\\1'>\\2</span>";
;)
Refer to preg_replace [us2.php.net] Example 2: Using indexed arrays with preg_replace().
The format will be similar to the pattern I wrote above. This thread [webmasterworld.com] has some examples as well as some of the threads in the search from my first post.
<?php
function bbcode2html($strInput) {
return preg_replace(
array(
'/\\[url[\\:\\=]((\\"([\\W]*javascript\:[^\\"]*)?([^\\"]*)\\")¦'.
'(([\\W]*javascript\:[^\\]]*)?([^\\]]*)))\\]/ie', '/\\[\\/url\\]/i',
'/\\[b\\]/i', '/\\[\/b\\]/i',
'/\\[i\\]/i', '/\\[\/i\\]/i',
'/\\[quote\\]/i', '/\\[\/quote\\]/i'
),
array(
'\'<a href="\'.(\'$4\'?\'$4\':\'$7\').\'">\'', '</a>',
'<strong>', '</strong>',
'<em>', '</em>',
'<blockquote>', '</blockquote>'
),
$strInput
);
}
?>