如何使用php DOM文档? [英] How to use php DOM document?
本文介绍了如何使用php DOM文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以发布一个示例,您可以用这个DOM文档类解析一个带有HTML的字符串变量?
Can anyone post a example where you parse a string variable with html in it with this DOM document class?
我需要从此变量中删除某些标签。
I need to remove certain tags from this variable..
没有关于如何在PHP网站上使用的例子
There are no examples on how to use it on the PHP website
推荐答案
$document = new \DomDocument('1.0', 'UTF-8');
$document->loadHTML($source);
$rootElement = $document->documentElement;
$unwantedTags = $rootElement->getElementsByTagName('a');
foreach($unwantedTags as $tag)
{
$tag->parentNode->removeChild($tag);
}
这篇关于如何使用php DOM文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文