php读取xml出现 错误:“parser error : CData section not finished”问题
原因是该XML上有一些无效字符。试试下面的代码
$url = 'http://noticias.perfil.com/feed/'; $html = file_get_contents($url); $invalid_characters = '/[^\x9\xa\x20-\xD7FF\xE000-\xFFFD]/'; $html = preg_replace($invalid_characters, '', $html); $xml = simplexml_load_string($html); //test purpose part $encode = json_encode($xml); $decode = json_decode($encode, true); print_r($decode);
原答案:https://stackoverflow.com/questions/44250530/how-to-read-this-xml-get-parser-error-cdata-section-not-finished