Jump to content

BBCode Help


ShoeLace1291

Recommended Posts

I just wrote a BBCode script for my application, but I have no idea why it's returning this error:

 

Delimiter must not be alphanumeric or backslash in W:\wamp\www\sources\global.source.php on line 250

 

Line 250 is the line that the preg_replace function is called on.  This is the code:

 

$bb_search = array(
        '\[b\](*?)\[\/b\]',
        '\[i\](*?)\[\/i\]',
        '\[u\](*?)\[\/u\]',
        '\[ul\](*?)\[\/ul\]',
        '\[ol\](*?)\[\/ol\]',
        '\[li\](*?)\[\/li\]',
        '\[sub\](*?)\[\/sub\]',
        '\[sup\](*?)\[\/sup\]',
        '\[img]http://(*?)\[\/img\]',
        '\[url=(*?)\](*?)\[\/url\]'
        );
    
    $bb_replace = array(
        '<b>$1</b>',
        '<i>$1</i>',
        '<u>$1</u>',
        '<ul>$1</ul>',
        '<ol>$1</ol>',
        '<li>$1</li>',
        '<sub>$1</sub>',
        '<sup>$1</sup>',
        '<img src=\'$1\' alt=\'Image Not Available\'>',
        '<a href=\'$1\' title=\'\\2\'>\\2</a>'
        );
    
    $str = preg_replace($bb_search, $bb_replace, $str);

Link to comment
Share on other sites

Now it's returning this error:

 

Compilation failed: nothing to repeat at offset 14 in W:\wamp\www\sources\global.source.php on line 251

 

Here's the updated code:

 

$bb_search = array(
        '#\[b\](.*?)\[\/b\]#',
        '#\[i\](.*?)\[\/i\]#',
        '#\[u\](.*?)\[\/u\]#',
        '#\[ul\](.*?)\[\/ul\]#',
        '#\[ol\](.*?)\[\/ol\]#',
        '#\[li\](.*?)\[\/li\]#',
        '#\[sub\](.*?)\[\/sub\]#',
        '#\[sup\](.*?)\[\/sup\]#',
        '#\[img](.*?)\[\/img\]#',
        '#\[url=(.*?)\](*?)\[\/url\]#'
        );
    
    $bb_replace = array(
        '<b>$1</b>',
        '<i>$1</i>',
        '<u>$1</u>',
        '<ul>$1</ul>',
        '<ol>$1</ol>',
        '<li>$1</li>',
        '<sub>$1</sub>',
        '<sup>$1</sup>',
        '<img src=\'$1\' alt=\'Image Not Available\'>',
        '<a href=\'$1\' title=\'$2\'>$2</a>'
        );
    
    $str = preg_replace($bb_search, $bb_replace, $str);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.