04-06-2008, 02:09 PM
|
#7 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
"However, this will mean that you will have no capitals at all in your string."
Why not just do a case insensitive search by adding "i" to the end of your regular expression?
/\[b\](.*)\[\/b\]/i
Or worst come to worst, you should be able to group them.
/\[[Bb]\](.*)\[\/[Bb]\]/
Your new code with both possibilities would look like this:
PHP Code:
function bbcode($input){
$pattern[0] = "/\[[Bb]\](.*)\[\/[Bb]\]/";
$pattern[1] = "/\[url\=(.*)\](.*)\[\/url\]/i";
$replace[0] = "<strong>$1</strong>";
$replace[1] = "<a href=\"$1\">$2</a>";
echo preg_replace($pattern, $replace, $input);
}
bbcode("[b]hello![/b] [url=http://localhost/]LOCALHOST!![/url]");
(note: not sure why, but the first B and last URL are capitalized on my end, but they get lowercased on output)
|
|
|
|