RobertP Posted June 20, 2012 Share Posted June 20, 2012 why is this not working? http://gskinner.com/RegExr/?31a9l preg_replace(): Unknown modifier 'b' <?php $string = 'This is a [b]simple BBCode[/b] test. This is another test [b]line[/b]. [b]tt[/b]'; $string = preg_replace('/\[b](.*)\[/b]/gi','<span style="font-size:bold;">$1</span>',$string); echo str_replace("\n",'<br />',$string); ?> Link to comment https://forums.phpfreaks.com/topic/264472-bbcode-issue/ Share on other sites More sharing options...
JAY6390 Posted June 20, 2012 Share Posted June 20, 2012 change [/b] to [\/b] Link to comment https://forums.phpfreaks.com/topic/264472-bbcode-issue/#findComment-1355332 Share on other sites More sharing options...
xyph Posted June 20, 2012 Share Posted June 20, 2012 A 'better' solution would be to use a different delimiter. Escaping delimiters within the expression when you don't have to just adds complexity. http://php.net/manual/en/regexp.reference.delimiters.php '~\[b](.*)\[/b]~gi' Link to comment https://forums.phpfreaks.com/topic/264472-bbcode-issue/#findComment-1355553 Share on other sites More sharing options...
RobertP Posted June 20, 2012 Author Share Posted June 20, 2012 A 'better' solution would be to use a different delimiter. Escaping delimiters within the expression when you don't have to just adds complexity. http://php.net/manual/en/regexp.reference.delimiters.php '~\[b](.*)\[/b]~gi' Amazing resource, thank you very much! Link to comment https://forums.phpfreaks.com/topic/264472-bbcode-issue/#findComment-1355555 Share on other sites More sharing options...
xyph Posted June 20, 2012 Share Posted June 20, 2012 Yeah... the manual does kinda rock. Link to comment https://forums.phpfreaks.com/topic/264472-bbcode-issue/#findComment-1355557 Share on other sites More sharing options...
RobertP Posted June 20, 2012 Author Share Posted June 20, 2012 so, is it possible to make this expression any simpler? /\[b\](.*?)\[\/b\]/is i tried this, but i want to remove the backward slashes completely if possible. #\[b](.*?)\[/b]#is Link to comment https://forums.phpfreaks.com/topic/264472-bbcode-issue/#findComment-1355558 Share on other sites More sharing options...
xyph Posted June 20, 2012 Share Posted June 20, 2012 No, you will always have to escape the [. It's a special character within RegEx. You could make it it's own character class, but that will actually add complexity and slow down the RegEx [[]b](.*?)[[]/b] You could use a non-special character enclosure for your BBCode... {b}(.*?){/b} ... but that would change the behaviour of the application entirely. Link to comment https://forums.phpfreaks.com/topic/264472-bbcode-issue/#findComment-1355562 Share on other sites More sharing options...
RobertP Posted June 21, 2012 Author Share Posted June 21, 2012 Thank you very much. i think i am going to update my parser to use this method. much easier on the eyes after a few hours :S #\[b](.*?)\[/b]#is Link to comment https://forums.phpfreaks.com/topic/264472-bbcode-issue/#findComment-1355810 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.