怎么在PHP中将XML与数据格式进行转换

  介绍

怎么在PHP中将XML与数据格式进行转换?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

具体如下:

& lt; PHP ?      function  xml2array(内容、美元,美元get_attributes =, 1, $ priority =, & # 39;标签# 39;),{   if 才能;(! $内容),return 数组();   if 才能;(! function_exists(& # 39;作用# 39;)),{   ,,,//,print “& # 39;作用是()& # 39;,function  not 发现!“;   ,,,return 数组();   ,,},//才能,Get 从而XML  parser  of  PHP 作用;PHP  must  have 却;能够module  for 从而parser 用工作   时间=美元才能parser 作用(& # 39;& # 39;);   xml_parser_set_option才能(解析器,美元,XML_OPTION_TARGET_ENCODING,,“UTF-8");,//, http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss    xml_parser_set_option才能(解析器,美元,XML_OPTION_CASE_FOLDING,, 0);   xml_parser_set_option才能(解析器,美元,XML_OPTION_SKIP_WHITE,, 1);   xml_parse_into_struct才能(解析器,美元,削减(内容)美元,,xml_values美元);   xml_parser_free才能解析器($);   if 才能;(! $ xml_values),返回,,//嗯…,//初始化。才能   时间=美元才能xml_array 数组();   时间=美元才能parents 数组();   时间=美元才能opened_tags 数组();   时间=美元才能arr 数组();   美元才能current =,, xml_array美元;,//Refference //才能,Go  through 从而标签。   时间=美元才能repeated_tag_index 数组();,//Multiple  tags  with  same  name  will  be  turned  into  an  array    foreach才能(xml_values 美元;as  $数据),{   ,,,设置(属性、美元,美元值),,//Remove  existing 价值观,趁机there  will  be  trouble    ,,,//,却;能够command  will  extract  these  variables  into 从而foreach 范围   ,,,//,标签(字符串),类型(字符串),水平(int)、属性(数组)。   ,,,提取(元数据),,//We  could  use 从而array  by 本身,but 却;能够冷却器只   ,,,result 美元;=,数组();   ,,,attributes_data 美元;=,数组();   ,,,if (收取(值)美元),{   ,,,,,if  (priority 美元;==,& # 39;标签# 39;),result 美元;=,美元价值;   ,,,,,else 结果美元[& # 39;价值# 39;],=,美元价值;,//Put 从而value 拷贝a  assoc  array  if 断开连接,我方表示歉意,并拷贝& # 39;属性# 39;,mode    ,,,},   ,,,//,Set 从而attributes 。   ,,,if (收取(属性),以及get_attributes美元),{   ,,,,,foreach (attributes 美元;as  attr 美元;=祝辞,val美元),{   ,,,,,,,if  (priority 美元;==,& # 39;标签# 39;),attributes_data美元(美元attr),=, val美元;   ,,,,,,,else 结果美元[& # 39;attr # 39;][美元attr],=, val美元;,//Set  all 从而attributes 拷贝a  array  nbsp; & # 39; attr # 39;,   ,,,,,},   ,,,},   ,,,//,阅读tag  status 以及do 从而需要。   ,,,if  (type 美元;==,“open"),{//大敌;从而starting  of 从而tag  & # 39; & lt; tag> & # 39;   ,,,,,父母美元(1美元),=,,目前美元;   ,,,,,if  (! is_array(现在的美元),或(! in_array(标签,美元,中的(当前)美元))),{,//Insert  New 标记   ,,,,,,,目前美元($ tag),=,美元的结果;   ,,,,,,,if  (attributes_data美元),当前美元($ tag 只& # 39;_attr& # 39;],=, attributes_data美元;   ,,,,,,,repeated_tag_index美元($ tag 只& # 39;_ # 39;,只美元水平),=,1;   ,,,,,,,current 美元;=,,目前美元($ tag);   ,,,,,},else  {,//There  was  another  element  with 从而same  tag 名字   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

怎么在PHP中将XML与数据格式进行转换