...

View Full Version : BBcode Error?



UrbanTwitch
08-13-2008, 06:57 AM
It worked fine before but now I get the error:

Warning: preg_replace() [function.preg-replace]: Compilation failed: unmatched parentheses at offset 3 in /home/jsfdan/public_html/inbox.php on line 123

when i try to put an emoticon

Edit: I got an update....

I remove the following that I thought may be causing this error:

'#\:-)#se',
'#\<_<#se',
'#\:-(#se',
'#\^_^#se',

And it worked! But I wanted people to use :-) and <_<, etc for emitcons... is there a way round it?

<?php
function BBCODE($content){ //define the function of bbcode
$content = nl2br($content); //replaces returns with br's
$match = array(
'#\[b\](.*?)\[\/b\]#se',
'#\[i\](.*?)\[\/i\]#se',
'#\[u\](.*?)\[\/u\]#se',
'#\[s\](.*?)\[\/s\]#se',
'#\[url=(.*?)\](.*?)\[\/url\]#se',
'#\[url\](.*?)\[\/url\]#se',
'#\[img\](.*?)\[\/img\]#se',
'#\[code\](.*?)\[\/code\]#se',
'#\[php\](.*?)\[\/php\]#se',
'#\[html\](.*?)\[\/html\]#se',
'#\[print\](.*?)\[\/print\]#se',
'#\[center\](.*?)\[\/center\]#se',
'#\[right\](.*?)\[\/right\]#se',
'#\[left\](.*?)\[\/left\]#se',
'#\[justify\](.*?)\[\/justify\]#se',
'#\:wink:#se',
'#\:angry:#se',
'#\:biggrin:#se',
'#\:blink:#se',
'#\:blush:#se',
'#\:cool:#se',
'#\:cry:#se',
'#\:eh:#se',
'#\^_^#se',
'#\<_<#se',
'#\:lol:#se',
'#\:omg:#se',
'#\:mellow:#se',
'#\:ninja:#se',
'#\:rolleyes:#se',
'#\:no:#se',
'#\:suspect:#se',
'#\:-)#se',
'#\;-)#se',
'#\:worried:#se',
'#\:king:#se',
'#\:wub:#se'
); //codes used in posts
$replace = array(
"'<b>\\1</b>'",
"'<i>\\1</i>'",
"'<u>\\1</u>'",
"'<s>\\1</s>'",
"'<a href=\"\\1\" target=\"_BLANK\">\\2</a>'",
"'<a href=\"\\1\" target=\"_BLANK\">\\1</a>'",
"'<img border=\"0\" src=\"\\1\">'",
"'<u><b>Code:</b></u>
<div style=\"border: 1px dotted #000000; width: 370px; background-color: #CCCCCC;\">
'.highlight_string(stripslashes(str_replace('', '', '$1')), true).'</div>'",
"'<u><b>PHP Code:</b></u>
<div style=\"border: 1px solid #42AC47; width: 370px;background-color: #B1E2B4;> '.highlight_string(stripslashes(str_replace('', '', '$1')), true).'</div>'",
"'<u><b>HTML Code:</b></u>
<div style=\"border: 1px solid #42AC47; width: 370px;background-color: #CCCCCC;> '.highlight_string(stripslashes(str_replace('', '', '$1')), true).'</div>'",
"'<u><b>Print Out:</b></u>
<div style=\"border: 1px dotted #000000; width: 370px; background-color: #CCCCCC;>
'.highlight_string(stripslashes(str_replace('', '', '$1')), true).'</div>'" ,
"'<div style=\"text-align:center;\">\\1</div>'",
"'<div style=\"text-align:right;\">\\1</div>'",
"'<div style=\"text-align:left;\">\\1</div>'",
"'<div style=\"text-align:justify;\">\\1</div>'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/wink.gif\">'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/angry.gif\">'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/biggrin.gif\">'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/blink.gif\">'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/blush.gif\">'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/cool02.gif\">'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/crying_anim02.gif\">'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/eh.gif\">'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/happy.gif\">'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/jealous.gif\">'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/laughingsmiley.gif\">'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/lmaosmiley.gif\">'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/mellow.gif.gif\">'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/ph34r.gif\">'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/rolleyes_anim.gif\">'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/sad01_anim.gif\">'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/shiftyeyes_anim.gif\">'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/smile.gif\">'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/wink2.gif\">'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/worried_anim.gif\">'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/king.gif\">'",
"'<img border=\"0\" src=\"http://sodadome.com/b/s/wub_anim.gif\">'"
); //replacements
return preg_replace($match, $replace, $content); //match, and replace
} //end the function
?>

I must be putting something extra I am not seeing. :\

Fou-Lu
08-13-2008, 07:39 AM
'#\:-)#se',
'#\<_<#se',
'#\:-(#se',
'#\^_^#se',

Its the ) or ( characters that cause this. ( and ) are reserved in patterns for capturing subpatterns. Escape them and it will work like gold.

UrbanTwitch
08-13-2008, 08:28 AM
Yeah, but how do I do that? (escape the ( and ))

Fou-Lu
08-13-2008, 08:37 AM
With a \ character before the ( and )



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum