考虑以下:
$string = "A string with {LABELS} and {more|232} {lbls} and some other stuff";
echo str_replace('/(\{.*?\})/', '', $string);
Run Code Online (Sandbox Code Playgroud)
我正在尝试删除所有标签(标签之间是任何文字{brackets}).预期的产出是:
A string with and and some other stuff
Run Code Online (Sandbox Code Playgroud)
但我得到的是原始字符串:
A string with {LABELS} and {more|232} {lbls} and some other stuff
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
Ger*_*rry 11
str_replace不能使用正则表达式,而是使用preg_replace:
http://php.net/manual/en/function.preg-replace.php