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
https://forums.phpfreaks.com/topic/264142-bbcode-help/
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
https://forums.phpfreaks.com/topic/264142-bbcode-help/#findComment-1353649
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.