2015年3月11日水曜日

xml変換

  1. //--------------------------------------------------------------  
  2. // xmlを連想配列で返す  
  3. // php変数不可文字対応 英数字以外はすべて_へ変換  
  4. //--------------------------------------------------------------  
  5. function simplexml_load_string2array($xmlstr){  
  6.     // 不正文字コードの除去   
  7.     $res=preg_match_all("/<([^>]+)>/i",$xmlstr,$matches);  
  8.     $tags=$matches[1];  
  9.     for($i=0;$i<count($tags)-1;$i++){ ペアタグのとき="" if('="" '.$tags[$i]="=$tags[$i+1]){" $replaced="preg_replace("/[^0-9a-zA-Z_]+/","_",$tags[$i]);" 英数字_以外有り="" if($tags[$i]!="$replaced){" $xmlstr="str_replace($tags[$i],$replaced,$xmlstr);" }="" ペア分次スキップ="" $i++;="" $xml="simplexml_load_string($xmlstr);" true);="" return="" $xml;="" <="" pre="">  
  10. <div style="clear: both;"></div>  
  11. </count($tags)-1;$i++){>