PHP to obtain xml output from remote pages

Source: Internet
Author: User
To obtain the xml output from a remote page, PHP needs to obtain the xml output from a remote page. in addition to the xml code, the page header has other problematic information. use simplexml_load_string () if you get this content, the error message "Entity: line1: parsererror: Starttage PHP" is used to obtain the xml output from the remote page.
You need to obtain the xml output from a remote page. besides the xml code, the page header has other problems,

If simplexml_load_string () is used to obtain this content, the system prompts Entity: line 1: parser error: Start tag expected, '<' not found

Is there any other way to get this information, or you don't need to parse the xml file, as long as you determine The content in can also be

XML code
HTTP/1.1 200 OKServer: Apache-Coyote/1.1Content-Type: application/xml; charset = UTF-8Content-Length: 662 Date: Wed, 28 Mar 2012 02:04:43 GMTConnection: close
  
  
   
    
Sign
   
   
    
1B6DF27CC81E98EEBE78F5E4765F2E09
   
   
    
Timestamp
   
   
    
20120328100423
   
   
    
V
   
   
    
1.0
   
   
    
Sign_v
   
   
    
1
   
   
    
Method
   
   
    
Allinpay. card. cardwithproductinfo. get
   
   
    
App_key
   
   
    
Test
   
   
    
Format
   
   
    
Xml
   
   
    
Password
   
   
    
5arHL6zxgecGKGQ nqBVQPRth3zEuJMO
   
   
    
Card_id
   
   
    
12345678
   
   25
   
    
Invalid signature
   
  


------ Solution --------------------
1. I don't know what method you used to obtain it. why don't I remove the header information?
2. simplexml_load_file supports URLs and can be obtained directly. why should we capture strings first?

------ Solution --------------------
Try it now.
PHP code
$ String = <
  
   
    
Sign
   
   
    
1B6DF27CC81E98EEBE78F5E4765F2E09
   
   
    
Timestamp
   
   
    
20120328100423
   
   
    
V
   
   
    
1.0
   
   
    
Sign_v
   
   
    
1
   
   
    
Method
   
   
    
Allinpay. card. cardwithproductinfo. get
   
   
    
App_key
   
   
    
Test
   
   
    
Format
   
   
    
Xml
   
   
    
Password
   
   
    
5arHL6zxgecGKGQ nqBVQPRth3zEuJMO
   
   
    
Card_id
   
   
    
12345678
   
   25
   
    
Invalid signature
   XML; echo'
   
'; $ Xml = simplexml_load_string ($ string); var_dump ($ xml );
------ Solution --------------------
You can use file_get_contents ('AA. XML'); then obtain the regular expression.

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.