Tar*_*yen 4 php xml simplexml cdata
我试图读取此xml: xml rss文件
但是没有成功..有这个错误
Warning: simplexml_load_file(): http://noticias.perfil.com/feed/:232: parser error : CData section not finished <p>La sola lectura de los datos estadísticos desp in D:\xampp\FerreWoo\scrap-rvnot.php on line 43
Warning: simplexml_load_file(): Isis, con lo que habría logrado un nuevo respaldo a sus proyectos terroristas. in D:\xampp\FerreWoo\scrap-rvnot.php on line 43
Warning: simplexml_load_file(): ^ in D:\xampp\FerreWoo\scrap-rvnot.php on line 43
Run Code Online (Sandbox Code Playgroud)
我正在使用此代码:
$feed = simplexml_load_file($urls, null, LIBXML_NOCDATA);
Run Code Online (Sandbox Code Playgroud)
我也尝试使用cURL,但是仍然出现相同的错误。
我知道de xml文件可能不正确...但是必须有一种读取方法,对吗?
小智 6
您在该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);
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你
| 归档时间: |
|
| 查看次数: |
1559 次 |
| 最近记录: |