簡體   English   中英

DOMDocument和DOMXPath錯誤

[英]DOMDocument and DOMXPath error

我想使用DOMDocument映射所有區域形狀標簽,但是我的代碼僅適用於DIV,而不適用於map標簽。 為什么? 這是我的代碼。 我得到的問題是返回空字符串。

碼:

$DOM = new DOMDocument; 
$DOM->loadHTML($conteudo['ambiente']->mapeamento);
$xpath = new DOMXPath($DOM);
$tags = $xpath->query('//area');
foreach ($tags as $tag) {
    var_dump(trim($tag->nodeValue));
}

示例代碼:

<map name="Map" id="Map">
  <area shape="poly" coords="0,916,86,880,527,854,520,819,536,818,547,818,564,819,563,855,627,851,620,813,640,810,653,810,664,813,660,847,804,837,816,820,766,823,756,821,752,815,743,414,755,407,782,406,1282,430,1286,432,1279,775,1290,775,1306,775,1311,777,1305,804,1337,801,1335,775,1341,772,1353,772,1370,774,1370,797,1711,793,1792,802,1789,365,1795,360,1804,0,-1,0,0,916,1,915,1144,804" href="#" />
  <area shape="poly" coords="1143,803,1271,792,1274,808,1151,816,1143,812,1142,803" href="#" />
  <area shape="poly" coords="1800,-1,2052,-1,2054,1033,1907,1003,1909,973,2024,967,2016,315,1866,328,1794,360,1803,2" href="#" />
  <area shape="poly" coords="1899,975,1894,1002,1876,998,1879,974,1901,974" href="#" />
</map>

您的<area>標記沒有內容,因此輸出正確。 如果要獲取coords屬性的值,則應使用

$tags = $xpath->query('//area/@coords');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM