$url = 'http://221.232.141.108/hsdcw/news.xml'; $opts = array( 'http'=>array( 'method'=>"GET", 'timeout'=>10, ) ); $context = stream_context_create($opts); $str = file_get_contents($url, false, $context); $str = trim($str); $xml = simplexml_load_string($str,'SimpleXMLElement', LIBXML_NOCDATA); $j = json_encode($xml); file_put_contents('/news.log',$j);