Home > Article > Backend Development > php processing method for obtaining xml interface data
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!