php - PHP使用特定标签删除div及其子元素
问题描述
PHP中有没有办法从内容中删除具有特定类的所有div并返回结果,例如我有这个代码:
<?php
$content = '<div class="toRemove">
content here
bla bla
<div class="toBeRemoved">content here also</div>
<div class="test">content ...</div>
lorem ipsum dolor sit ...
other divs here with different classes and ids
</div>
<div class="otherInfo">....</div>
';
$content = preg_replace('#<div class="toRemove">([\s\S]*?)</div>#','', $content); // tried this but did work as I wanted to
echo $content;
我想要的是使用 toRemove 类删除 div 内的所有内容,我得到的是未删除子 div 的内容!
提前感谢您的帮助。
解决方案
推荐阅读
- ios - Swift - CollectionViewCell 边框错误或不完整
- azure-devops - VSTS Windows 机器文件复制 robocopy 未找到
- sql - 如何获取列值的总和作为 SQL 结果集中的新列
- javascript - 如何更改猫头鹰轮播中的视频背景图像?
- javascript - 不稳定的鼠标进入/鼠标离开子菜单
- r - R: na 在 ifelse
- azure - 具有任意磁盘大小的托管磁盘计费
- mysql - 这段 SQL 代码有什么问题?(VBA MS 访问)
- javascript - 改变动态添加的js对象的值
- codeigniter - 我正在处理项目,我的 rsult 查询给出了多条记录,但我只想一次记录每条记录,我在这个查询中使用了内部联接?