好的,xml文件看起来像这样,它被设置为一个变量$otherdata
<result>
<sighting>
<name>Johhny</name>
<last>smith</last>
<phone>5551234</phone>
</sighting>
</result>
和 php 代码看起来像这样
$dom = new DOMDocument;
$dom ->load($otherdata);
$xpath = new DomXpath($dom);
$query = '//result/sighting[name = "Johhny"]/.';
$entries = $xpath->query($query);
foreach ($entries as $entry) {
$newlat = $entry->textContent;
echo $newlat
}
我遇到麻烦的地方是尝试获取“last”和“phone”属性中的值并将其设置为等于变量以稍后存储和回显...谢谢