Home  >  Article  >  Backend Development  >  php processing method for obtaining xml interface data

php processing method for obtaining xml interface data

不言
不言Original
2018-05-31 15:00:411824browse

This article mainly introduces the processing method of php to obtain xml interface data. It has certain reference value. Now I share it with you. Friends in need can refer to it

xml The format of the data returned is generally like this, but there are also differences:

<?xml version="1.0" encoding="gbk"?> 
<root> 
  <head> 
   <actdate>20170805</actdate> 
   <trdate>20170805</trdate> 
   <trtime>142410</trtime> 
   <trseq>20170807001</trseq> 
   <succflag>1</succflag> 
   <retcode>0000</retcode> 
   <retmsg>鎴愬姛</retmsg> 
  </head> 
  <body> 
   <rowcount>0</rowcount> 
  </body> 
</root>

Generally, xml is directly used in PHP: simplexml_load_string(); is parsed into an array, but when I parse it, it prompts: There is data encoding that cannot be parsed.

That’s the part where the data is garbled. I used the header statement to solve the garbled code, but it didn’t work. Finally I used:

iconv('utf-8' ,'gbk',$a);

To solve the problem, transcode first, then parse

and finally json conversion.

Related recommendations:

Detailed explanation of the three methods of php to obtain POST data

PHP Get user behavior [IP/OS/URL/ Broswer] Reference code

The above is the detailed content of php processing method for obtaining xml interface data. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn