simplexmlelement-php How to get the value of simplexml_load_string

Source: Internet
Author: User

Problem

/** * Returns a node value for a string by node path * $res _data--xml format string * Return node parameter */function getdataforxml ($res _data, $node) {$xml = Simplexml_lo    Ad_string ($res _data);    $result = $xml->xpath ($node);    while (list (, $node) = each ($result)) {return $node; }}$_post = Array (' service ' = ' alipay.wap.trade.create.direct ', ' sign ' = = ' db56d137c71f591abd58b41 d5da5f920 ', ' sec_id ' = ' MD5 ', ' V ' = ' 1.0 ', ' notify_data ' = '
  
    
    
      1 
     
    
      recharge 
     
    
      2014123069117121 
     
    
      default@gmail.com  
     
       2014-12-30 22:12:32 
      
     
       trade_s
  Tatus_sync 
      
     
       1 
      
     
       1412302289443 
      
     
       2014-12-30 22:12:56 
      
     
       2088211987518229 
      
     
       trade_finished  
      
        N 
       
      
        0.11 
       
      
        2014-12-30 22:12:56 
       
      
        zfb@gmail.cn 
       
      
        2014-12-30 22:12:56 
      
 
      
        0.11 
       
      
        2088102193791211 
       
      
        8f3d3703e293b95d8de26cbd51d74fe116 
       
      
        N 
       
     
    
   
  ', '); $out _trade_no = Getdataforxml ($_post[' notify_data '), '/notify/out_trade_no '); Var_dump ($out _trade_no = = ' 1412302289443 ')); Truevar_dump ($out _trade_no);//object (SimpleXMLElement) [2]

How can I get the value of $out _trade_no

Reply content:

Problem

/** * Returns a node value for a string by node path * $res _data--xml format string * Return node parameter */function getdataforxml ($res _data, $node) {$xml = Simplexml_lo    Ad_string ($res _data);    $result = $xml->xpath ($node);    while (list (, $node) = each ($result)) {return $node; }}$_post = Array (' service ' = ' alipay.wap.trade.create.direct ', ' sign ' = = ' db56d137c71f591abd58b41 d5da5f920 ', ' sec_id ' = ' MD5 ', ' V ' = ' 1.0 ', ' notify_data ' = '
  
    
    
      1 
     
    
      recharge 
     
    
      2014123069117121 
     
    
      default@gmail.com  
     
       2014-12-30 22:12:32 
      
     
       trade_s
  Tatus_sync 
      
     
       1 
      
     
       1412302289443 
      
     
       2014-12-30 22:12:56 
      
     
       2088211987518229 
      
     
       trade_finished  
      
        N 
       
      
        0.11 
       
      
        2014-12-30 22:12:56 
       
      
        zfb@gmail.cn 
       
      
        2014-12-30 22:12:56 
      
 
      
        0.11 
       
      
        2088102193791211 
       
      
        8f3d3703e293b95d8de26cbd51d74fe116 
       
      
        N 
       
     
    
   
  ', '); $out _trade_no = Getdataforxml ($_post[' notify_data '), '/notify/out_trade_no '); Var_dump ($out _trade_no = = ' 1412302289443 ')); Truevar_dump ($out _trade_no);//object (SimpleXMLElement) [2]

How can I get the value of $out _trade_no

SimpleXML Parse is the Simpleelement object, need type conversion, such as the way the son said the method can be

$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.