How does simplexmlelement-PHP get the value of simplexml_load_string?

Source: Internet
Author: User
Question {code...} How can I get the value of $ out_trade_no?
/*** Return a node value of the string through the node path * $ res_data -- XML format string * return node parameter */function getDataForXML ($ res_data, $ node) {$ xml = simplexml_load_string ($ res_data); $ result = $ xml-> xpath ($ node); while (list (, $ node) = each ($ result )) {return $ node ;}$ _ POST = array ('service' => 'alipay. wap. trade. create. direct ', 'sign' => 'db56d137c71f591abd58b41d5da5f920', 'sec _ id' => 'md5', 'V' => '1. 0', 'Your Y _ data' =>'
  
   
    
1
   
   
    
Recharge
   
   
    
2014123069117121
   
   
    
Default@gmail.com
   
   
    
22:12:32
   
   
    
Trade_status_sync
   
   
    
1
   
   
    
1412302289443
   
   
    
22:12:56
   
   
    
2088211987518229
   
   
    
TRADE_FINISHED
   
   
    
N
   
   
    
0.11
   
   
    
22:12:56
   
   
    
Zfb@gmail.cn
   
   
    
22:12:56
   
   
    
0.11
   
   
    
2088102193791211
   
   
    
8f3d3703e293b95d8de26cbd51d74fe116
   
   
    
N
   
  ',); $ Out_trade_no = getDataForXML ($ _ POST ['your Y _ data'],'/your Y/out_trade_no '); var_dump ($ out_trade_no = '000000'); // truevar_dump ($ out_trade_no); // object (SimpleXMLElement) [2]

How can I get the value of $ out_trade_no?

Reply content: Question
/*** Return a node value of the string through the node path * $ res_data -- XML format string * return node parameter */function getDataForXML ($ res_data, $ node) {$ xml = simplexml_load_string ($ res_data); $ result = $ xml-> xpath ($ node); while (list (, $ node) = each ($ result )) {return $ node ;}$ _ POST = array ('service' => 'alipay. wap. trade. create. direct ', 'sign' => 'db56d137c71f591abd58b41d5da5f920', 'sec _ id' => 'md5', 'V' => '1. 0', 'Your Y _ data' =>'
  
   
    
1
   
   
    
Recharge
   
   
    
2014123069117121
   
   
    
Default@gmail.com
   
   
    
22:12:32
   
   
    
Trade_status_sync
   
   
    
1
   
   
    
1412302289443
   
   
    
22:12:56
   
   
    
2088211987518229
   
   
    
TRADE_FINISHED
   
   
    
N
   
   
    
0.11
   
   
    
22:12:56
   
   
    
Zfb@gmail.cn
   
   
    
22:12:56
   
   
    
0.11
   
   
    
2088102193791211
   
   
    
8f3d3703e293b95d8de26cbd51d74fe116
   
   
    
N
   
  ',); $ Out_trade_no = getDataForXML ($ _ POST ['your Y _ data'],'/your Y/out_trade_no '); var_dump ($ out_trade_no = '000000'); // truevar_dump ($ out_trade_no); // object (SimpleXMLElement) [2]

How can I get the value of $ out_trade_no?

var_dump( (String)$out_trade_no ); 

Simplexml parses the simpleElement object and needs to convert the type, as described in the method described by struct.

$doc = new DOMDocument();$doc->loadXML($_POST['notify_data']);$doc->getElementsByTagName( "out_trade_no" )->item(0)->nodeValue;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.