我需要从动态的content.The id字段中删除[masterslider id="?"],如下所示
[masterslider id="161"]乔德普夫妇的家在这里交换他们的誓言,他们的客人也可以在Jiva Grande Spa享受令人愉悦的签名治疗和疗法,或者通过瑜伽和冥想舒缓他们的身心。[masterslider id="69"]。我试过了
$content=preg_replace('/[[\s\S]+?]/', '', $items['post_content']);发布于 2020-02-28 18:46:08
您可以尝试:
$content=preg_replace('/\[.*?\]/', '', $items['post_content']);`发布于 2020-02-28 20:16:24
尝试:
$content=preg_replace('/\[masterslider\s*id=".*?"\]/', '', $items['post_content']);
解释:
preg_replace('/\[masterslider\s*id=".*?"\]/', '', $items['post_content']);
^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^
1 2 3 4(1) preg_replace是一个使用正则表达式而不是静态字符串的函数(基本上它是str_replace的扩展版本)
(2)匹配此正则表达式(str_replace上的搜索/第二个参数)将匹配[ \[masterslider\s*=".*?"\] id=“(任何idor字符串)”]
(3)这是替换( '' /str_replace上的第3个参数)
(4) $items['post_content']是主题(文本/str_replace上的第一个参数)
为我糟糕的解释道歉
https://stackoverflow.com/questions/60449990
复制相似问题