我通过简单的HTML解析器或simple_html_dom.php获取页面。我只得到图像h1 h2 h3和p元素在页面中,我想从锚标记中删除href属性。但是得到错误。根据官方文档,语法是…
删除一个属性,将它的值设置为null!
$e->href = null;
但是我得到错误。这是我的代码。
<?php
include_once('simple_html_dom.php');
$html = file_get_html('http://www.lifehacker.com/');
$html=$html->find('h1 , h2 , h3 ,img, p');
$html->a["href"]=null;
foreach($html as $elements){
echo $elements.'<br>';
}
我想从每个元素中删除href。意味着只有链接出现,但用户不应该打开它或瞄准它。
更新:当您只检查锚时,它会给您想要的结果吗?
foreach($html->find('a') as $element) {
if (isset($element->href)) {
$element->href = null;
}
}
echo $html;