时间:2021-07-01 10:21:17 帮助过:14人阅读
$xml=simplexml_load_file('bb.xml'); foreach($xml->item as $v){ if($v->id==4) echo "id : $v->id
pd : $v->pd"; }
------解决方案--------------------
xpath,还有其他答案吗。
[User:root Time:10:28:18 Path:/home/liangdong/php]$ php xpath.php pd B004 [User:root Time:10:28:19 Path:/home/liangdong/php]$ cat xpath.php1 B007 2 B001 3 B000 4 B004 - EOF; $xml = simplexml_load_string($str, "SimpleXMLElement", LIBXML_NOBLANKS); $res = $xml->xpath("/channel/item/id[text()=4]/parent::item/pd"); foreach ($res as $node) { echo $node->getName() . " " . $node->{0} . PHP_EOL; } ?>
5 B003