You have to escape all occurances of /
inside the outer /
delimiters of your regex.
So you are probably looking for this:
preg_replace("/\\[img]([^\\[]*)\\[\/img]/",
"<img src=\"\\1\" border=\"0\">",
$text);
Otherwise the regex engine will treat the expression as terminated here at the second /
:
/\\[img]([^\\[]*)\\[/
Whatever follows will be treated as modifiers to the expression. i
and m
do exist, g
does not exist. That is why an error is thrown whilst compiling the regex.
Alternatively you can use another delimiter character beside /
. But you have to make sure that character does not occur unescaped inside the expression itself. If the expression is not a literal string but comes from a variable then the preg_quote()
function comes in handy.