Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: BBcode Error?

  1. #1
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post

    BBcode Error?

    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 Code:
    <?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. :\
    Last edited by UrbanTwitch; 08-13-2008 at 07:07 AM.
    Formerly MysticScript

    6+ years club

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    '#\:-)#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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post
    Yeah, but how do I do that? (escape the ( and ))
    Formerly MysticScript

    6+ years club

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    With a \ character before the ( and )
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •