Ask a question about xml to php array. I want to receive xml content now, not the file content received by the file in the following format? & Lt ;? Xml & nbsp; version = "1.0" & nbsp; encoding = "UTF-8 "? & Gt; & lt; pReq> & lt; ax & gt; 0000 & lt;/ax & gt; & lt; at & gt: a question about converting xml to php arrays
I want to receive xml content, not a file
The content of the received file is in the following format:
? 0000Ax12711122233344212345Test402100002885328320130828 Note 1 Note 2 Note 3
How can I directly convert this code into a php array? this is not a file but a variable
Share xml php: 0000
------ Solution --------------------
Find a function named xml_to_array, such
Http://www.cnblogs.com/heiing/archive/2009/12/31/1637015.html
Then use it
Function xml_to_array ($ xml)
{
$ Reg = "/<(\ w +) [^>] *?> ([\ X00-\ xFF] *?) <\/\ 1> /";
If (preg_match_all ($ reg, $ xml, $ matches ))
{
$ Count = count ($ matches [0]);
$ Arr = array ();
For ($ I = 0; $ I <$ count; $ I ++)
{
$ Key = $ matches [1] [$ I];
$ Val = xml_to_array ($ matches [2] [$ I]); // recursion
If (array_key_exists ($ key, $ arr ))
{
If (is_array ($ arr [$ key])
{
If (! Array_key_exists (0, $ arr [$ key])
{
$ Arr [$ key] = array ($ arr [$ key]);