php - 如果它包含字符串,如何删除整个句子?PHP
问题描述
我正在尝试通过删除与我没有的其他文本相关的某些短语来使用 PHP 清理大文本。这些短语通常位于两个 html 标记之间,例如<i>this</i>
,但我只想删除那些包含关键字的短语,即“另见”。
有没有办法用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>
需要注意的是“另见”。
谢谢!
解决方案
这就是我解决它的方法:
$text = preg_replace("/<i>(See also)([^<]*)<\/i>/i",'', $text);
推荐阅读
- qt - 为什么带有 CmakeList 的 Qt 无法在设计选项卡中加载导入的 QML 组件?
- powershell - 复制重命名移动文件powershell
- julia - 如何让 Automa.jl 接受来自标准输入的输入?
- javascript - iframe Vimeo 视频结束屏幕按钮操作更改
- raspberry-pi - 在 Raspberry Pi 上安装新的 Linux 发行版
- react-native - 反应原生问题
- python - python for循环没有遍历字典列表的所有索引
- android-studio - Android Studio:如何关闭快捷方式列表选项卡
- base64 - 12C BPEL 中的 Base64 编码正在用 BPEL 变量名替换父标记
- mysql - 如何将 MySQL 的响应添加到 Redux?