[英]Remove all href of page by simple html dom
我正在通過簡單的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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.