解析xml文件

function sxe($url)
    {   
        $xml = file_get_contents($url);
        foreach ($http_response_header as $header)
        {   
            if (preg_match('#^Content-Type: text/xml; charset=(.*)#i', $header, $m))
            {   
                switch (strtolower($m[1]))
                {   
                    case 'utf-8':
                        // do nothing
                        break;

                    case 'iso-8859-1':
                        $xml = utf8_encode($xml);
                        break;

                    default:
                        $xml = iconv($m[1], 'utf-8', $xml);
                }
                break;
            }
        }

        return simplexml_load_string($xml);
    }

 

posted @ 2013-11-11 19:02  不负韶华668  阅读(184)  评论(0编辑  收藏  举报