Jump to content

BBCode Issue


RobertP

Recommended Posts

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

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

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.