How PHP parses the data returned by the WEBSERVICES interface-php Tutorial

Source: Internet
Author: User
PHP how to parse the WEBSERVICE interface returned data WEBSERVICE server, they wrote an interface http://XXX.XXX.XXX.XX/Info.asmx with. net? Wsdl
I used PHP to call this interface.
Try {$ wsdl = "http://XXX.XXX.XXX.XX/Info.asmx? Wsdl "; $ client = new SoapClient ($ wsdl); $ param = array ('strname' => 'Wu Xiaoming ', 'stridcard' => '4528xxxxxxxx ', 'descipare' => '123'); $ res = $ client-> GetBasicInfo ($ param); print_r ($ res);} catch (SOAPFault $ e) {var_dump ($ e );}

The following result is displayed:
StdClass Object ([GetBasicInfoResult] => stdClass Object ([any] =>
   
    
   
      
       
      
        
         
         
         
         
         
         
         
         
         
         
         
         
         
         
        
        
        
     
      
     
  
 
   
  
     
    
     
4507 ............
      
    
     
4507 ............
      
    
     
Wu ......
      
    
     
Male
      
    
     
4528 ............
      
    
     
1966-03-10T00: 00: 00 + 08: 00
      
    
     
Road ............
      
    
     
2011-05-23T00: 00: 00 + 08: 00
      
    
     
2011-05-23T00: 00: 00 + 08: 00
      
    
     
2017-05-22T00: 00: 00 + 08: 00
      
    
     
Qinzhou ............
      
    
     
AAA
      
    
     
C1 certificate
    
     
  
 ))


[Any] => It is not like a standard XML. How can I use PHP to obtain these values?


Reply to discussion (solution)

The data you provided lacks the root node. add it by yourself.

The data is divided into two parts: the first part is the data type declaration, and the second part is the data
What we care about is the second part.
Use SimpleXMLElement to obtain

SimpleXMLElement Object ([DocumentElement] => SimpleXMLElement Object ([Employee] => SimpleXMLElement Object ([ID_ECERT] => 4507 ............ [ECERTID] => 4507 ............ [NAME] => Wu ...... [SEX] => male [IDCARD] => 4528 ............ [BIRTHDAY] => 1966-03-10T00: 00: 00 + 08: 00 [ECERTAREA] => Road ............ [FIRSTDATE] => 2011-05-23T00: 00: 00 + 08: 00 [BEGINDATE] => 2011-05-23T00: 00: 00 + 08: 00 [ENDDATE] => 2017-05-22T00: 00: 00 + 08: 00 [GRANTORGAN] => Qinzhou ............ [CREDITLEVEL] => AAA [DRVLICENSE] => C1 certificate )))

The data you provided lacks the root node. add it by yourself.

The data is divided into two parts: the first part is the data type declaration, and the second part is the data
What we care about is the second part.
Use SimpleXMLElement to obtain

SimpleXMLElement Object ([DocumentElement] => SimpleXMLElement Object ([Employee] => SimpleXMLElement Object ([ID_ECERT] => 4507 ............ [ECERTID] => 4507 ............ [NAME] => Wu ...... [SEX] => male [IDCARD] => 4528 ............ [BIRTHDAY] => 1966-03-10T00: 00: 00 + 08: 00 [ECERTAREA] => Road ............ [FIRSTDATE] => 2011-05-23T00: 00: 00 + 08: 00 [BEGINDATE] => 2011-05-23T00: 00: 00 + 08: 00 [ENDDATE] => 2017-05-22T00: 00: 00 + 08: 00 [GRANTORGAN] => Qinzhou ............ [CREDITLEVEL] => AAA [DRVLICENSE] => C1 certificate )))


No.

The data you provided lacks the root node. add it by yourself.

The data is divided into two parts: the first part is the data type declaration, and the second part is the data
What we care about is the second part.
Use SimpleXMLElement to obtain

SimpleXMLElement Object ([DocumentElement] => SimpleXMLElement Object ([Employee] => SimpleXMLElement Object ([ID_ECERT] => 4507 ............ [ECERTID] => 4507 ............ [NAME] => Wu ...... [SEX] => male [IDCARD] => 4528 ............ [BIRTHDAY] => 1966-03-10T00: 00: 00 + 08: 00 [ECERTAREA] => Road ............ [FIRSTDATE] => 2011-05-23T00: 00: 00 + 08: 00 [GRANTORGAN] => Qinzhou ............ )))


Moderator. can you give an example?

Extract with regular expression

$s = preg_replace('/.+(
 
  GetBasicInfoResult->any);$xml = simplexml_load_string($s);print_r($xml);
 
The result of my example is displayed.

I thought I could get the data directly. I still needed to operate on the string. forget it. close the token.

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.