PHP SimpleXML函数的xpath问题


在centOS上装了apache 跟php

运行以下php文件

   
  <?php
  

$xml = simplexml_load_string("<note> <to> George </to> <from> <dt>John</dt> </from> <heading> Reminder </heading> <body type=\"small\" important=\"low\" > Don't forget the meeting! </body> <mm/>ddddddd </note>");

print("1 !!!!\n");
print_r( $xml->xpath('body'));

print("2 !!!!!!!!!!!\n");
print_r( $xml->xpath('/note'));

print("3 !!!!!\n");
print_r( $xml->xpath('/note/to'));

print("4 !!!!!!!!!!!\n");
print_r( $xml->xpath('/note/from'));
?>

输出

   
  [root@AY1212020301569343979 controllers]# php tt.php
  
Cannot load Zend Extension Manager - it was built with configuration 1.2.0, whereas running engine is API220100525,NTS
1 !!!!
Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => small
[important] => low
)

)

)
2 !!!!!!!!!!!
Array
(
[0] => SimpleXMLElement Object
(
[to] => George
[from] => SimpleXMLElement Object
(
[dt] => John
)

[heading] => Reminder
[body] => Don't forget the meeting!
[mm] => SimpleXMLElement Object
(
)

)

)3 !!!!!
Array
(
[0] => SimpleXMLElement Object
(
)

)
4 !!!!!!!!!!!
Array
(
[0] => SimpleXMLElement Object
(
[dt] => John
)

)

感觉所有结果都跟网上示例不同
比如根据网上的教程,第三个输出应该类似于

   
  3 !!!!!
  
Array
(
[0] => SimpleXMLElement Object
(
[0] => George
)zh

)

本来用到xpath的页面都是正常的,后来在服务器上用yum装了php-devel跟gcc,也不知道是不是装了这两个东西的缘故,所有用到xpath的地方返回的值都变成空的了

求教,到底哪儿出问题了

xml php

你是真皮虾发 10 years, 5 months ago

Your Answer