php读取xml

来源:互联网 发布:泉州专业淘宝拍摄 编辑:程序博客网 时间:2024/06/06 09:08
<?php$xml_url= 'http://wangfali.com/feed';// $xml_url= 'xml.xml';// simplexml_load_file读取// $xml_arr= simplexml_load_file(rawurlencode($xml_url), 'SimpleXMLElement', LIBXML_NOCDATA);// CDATA数据// $xml_arr= simplexml_load_file(rawurlencode($xml_url));// simplexml_load_string读取$xml_data= file_get_contents($xml_url);// $xml_data= str_replace("content:encoded>","content>", $xml_data);$xml_data= preg_replace("/<(\/?\w+):(\w+)>/","<$1_$2>", $xml_data);$xml_arr= simplexml_load_string($xml_data, 'SimpleXMLElement', LIBXML_NOCDATA);$xml_item= $xml_arr->channel->item;foreach($xml_item as $item){$item= (array)$item;var_dump($item);} ?>

0 0
原创粉丝点击