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

php processing method for obtaining xml interface data

不言
Release: 2023-03-28 17:34:01
Original
1843 people have browsed it

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template