如果包含字符串,如何删除整个句子? PHP

问题描述 投票:-2回答:1

我正在尝试通过使用PHP通过删除某些与我没有的其他文本相关的短语来清理大文本。这些词组通常位于两个HTML标记之间,例如<i>this</i>,但我只想删除那些包含关键字“ See also”的关键字。

是否可以通过preg_replace来做到这一点?

提供以下输入:

<h1>this is a header</h1>
<i>See also staying safe in Taiwan</i>
<p>Some long text here</p>
<i>Some more text over here</i>
<p>Some more text <i>here</i></p>

如何删除包含字符串“ 另请参见”的整个短语。预期输出:

<h1>this is a header</h1>
<p>Some long text here</p>
<i>Some more text over here</i>
<p>Some more text <i>here</i></p>

要注意的是“另请参见”。

谢谢!

php
1个回答
0
投票

这是我的解决方法:

$text = preg_replace("/<i>(See also)([^<]*)<\/i>/i",'', $text);
© www.soinside.com 2019 - 2024. All rights reserved.