<?PHP$content= <<<XML<?xml version= "1.0" encoding= "UTF-8"?> <test> <global_setting> <ping_protocol>http& Lt;/ping_protocol> <ping_port>80</ping_port> <PING_PATH>/INDEX.HTML</PING_PATH&G T <response_timeout>5000</response_timeout> XML; $test=NewSimpleXMLElement ($content); //get the value of Ping_protocol$ping _protocol=$test->global_setting->Ping_protocol; Echo"Ping_protocol:$ping _protocol\ n "; //print out IP for all instanceforeach($test->instances->instance as $instance) { Echo"IP: {$instance[' IP ']} \ n " ; }
//After my test, found that the trial var_dump and the like do not seem to be effective output value, with echo is smooth, there is the above XML example can be removed <?xml version= "1.0" encoding= "UTF-8"?> can also go to the end of the tail//or the <<<xml, and then treated as a normal string, but did not test Chinese and so on
PHP Parsing XML strings