ShoeLace1291 Posted June 14, 2012 Share Posted June 14, 2012 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); Quote Link to comment https://forums.phpfreaks.com/topic/264142-bbcode-help/ Share on other sites More sharing options...
scootstah Posted June 14, 2012 Share Posted June 14, 2012 Your patterns need delimiters at the beginning and end of them. '#\[b\](.*?)\[\/b\]#' Etc. EDIT: Your pattern is also incorrect, and won't match anything. You most likely want to put a period in the group. See the edited code above. Quote Link to comment https://forums.phpfreaks.com/topic/264142-bbcode-help/#findComment-1353643 Share on other sites More sharing options...
ShoeLace1291 Posted June 14, 2012 Author Share Posted June 14, 2012 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); Quote Link to comment https://forums.phpfreaks.com/topic/264142-bbcode-help/#findComment-1353649 Share on other sites More sharing options...
scootstah Posted June 14, 2012 Share Posted June 14, 2012 '#\[url=(.*?)\](*?)\[\/url\]#' You missed a period in the second group. Quote Link to comment https://forums.phpfreaks.com/topic/264142-bbcode-help/#findComment-1353653 Share on other sites More sharing options...
ShoeLace1291 Posted June 14, 2012 Author Share Posted June 14, 2012 Oh, haha forgot about that one... thanks for the help, though! Quote Link to comment https://forums.phpfreaks.com/topic/264142-bbcode-help/#findComment-1353654 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.