【发布时间】:2015-12-18 13:14:44
【问题描述】:
文本包含一些带有随机数的引号。
见:
$string = '[quote="Member123":hk1f9ynv]This is the quote Text and we want remove it.[/quote:hk1f9ynv]
Here is the anwser to the quote.
[quote:hk1f9ynv]Here is another quote, we want remove it too.[/quote:hk1f9ynv]
Thank you very much. Good job!';
编号:hk1f9ynv 存储在数据库中,是随机的。
输出应如下所示:
这里是引用的答案。非常感谢。干得好!
我在堆栈上尝试了许多解决方案。似乎没有任何效果。示例:
preg_replace('/\[[^>]*\]/', '', $string);
preg_replace('\[/?abc.*?\]', '', $string);
非常感谢。
【问题讨论】:
-
您尝试过类似
preg_replace('\[/?quote\:[a-zA-Z0-9]+\]', '', $string);的方法吗?我不确定'/' 你可能也需要使用'\'。 Obvisouly 你可以用你想要的替换 'quote'。 -
尝试了这两个选项。结果 --> 分隔符不能是字母数字或反斜杠
-
对不起!我忘了在结尾/开始时添加“/”。您必须添加它。
-
这样吗? preg_replace('[/?quote\:[a-zA-Z0-9]+]/', '', $string);
-
不,像这样:
preg_replace('/\[/?quote\:[a-zA-Z0-9]+\]/', '', $string);?
标签: php regex replace preg-replace