通过正则表达式剥离 BBCode

发布于 2024-11-03 02:26:29 字数 256 浏览 3 评论 0原文

我正在尝试设置一个正则表达式来检测 [quote]???[/quote] 并将其删除。

这就是我所拥有的,但它不起作用:

$post['body'] = preg_replace("/\[quote\](.+?)\[\/quote\]/is", '', $post['body']);

任何人都可以指出我正确的方向吗?

我还想删除 [quote]???[/quote] 之前或之后的所有线路制动器。

I am trying to setup a regex that will detect [quote]???[/quote] and will remove it.

This is what I have but it is not working:

$post['body'] = preg_replace("/\[quote\](.+?)\[\/quote\]/is", '', $post['body']);

Can anyone point me in the right direction?

I also want to remove any line brakes before or after the [quote]???[/quote].

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

焚却相思 2024-11-10 02:26:29

这是我对您的脚本的测试:

$text = "I am trying to setup a regex that will detect [quote]???[/quote] and will remove it.\r\nThis is what I have but it is not working:";
$sentences = preg_replace("/\[quote\](.+?)\[\/quote\]/is", '', $text);
echo '<pre>'.print_r($sentences, true).'</pre>';

我的输出:

I am trying to setup a regex that will detect  and will remove it.
This is what I have but it is not working:

您可以看到: [quote]???[/quote] 已删除。

我认为你的问题出在其他地方。检查 $post['body'] 的值!

也许这是拼写错误,您的意思是 $_POST['body']?

Here's my test with your script:

$text = "I am trying to setup a regex that will detect [quote]???[/quote] and will remove it.\r\nThis is what I have but it is not working:";
$sentences = preg_replace("/\[quote\](.+?)\[\/quote\]/is", '', $text);
echo '<pre>'.print_r($sentences, true).'</pre>';

And my Output:

I am trying to setup a regex that will detect  and will remove it.
This is what I have but it is not working:

You can see: [quote]???[/quote] is removed.

I think your problem is anywhere else. Check the Value of $post['body']!

Maybe it is a misspelling and you meen $_POST['body']?

行雁书 2024-11-10 02:26:29

刚刚弄清楚我自己的问题。

$post['body'] = preg_replace("/\[quote\](.+?)\[\/quote\]/is", '', $post['body']);
$body = trim(rtrim($post[0]['body']));

Just figured out my own issue.

$post['body'] = preg_replace("/\[quote\](.+?)\[\/quote\]/is", '', $post['body']);
$body = trim(rtrim($post[0]['body']));

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文