今天群里有人问,顺便实验了一下。
<?php $xml = " <node> <title src='hello'>world</title> </node> "; function get_data_from_xml($res_data,$node) { $xml = simplexml_load_string($res_data); $result = $xml->xpath($node); while(list( , $node) = each($result)) { return $node; } } // 'hello world'; echo get_data_from_xml($xml, '/node/title/@src[.]'), ' ' , get_data_from_xml($xml, '/node/title');