0

我想使用 DOMDocument 映射我所有的区域形状标签,但我的代码只适用于 DIV,而不适用于地图标签。为什么?这是我的代码。我得到的问题是返回空字符串。

代码:

$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>
4

1 回答 1

0

您的<area>标签没有内容,因此输出是正确的。如果要获取coords属性的值,则应使用

$tags = $xpath->query('//area/@coords');
于 2013-03-02T20:52:20.280 回答