SimpleXML解析器错误:"巨大的输入查找"

时间:2017-03-31 06:35:13

标签: php simplexml

我第一次使用PHP。我在运行PHP文件时遇到以下错误:

PHP Warning:  simplexml_load_string(): Entity: line 35909: parser error : internal error: Huge input lookup in /home/alisverispasaji/public_html/system/xml/minikoli/test.php on line 8

PHP Warning:  simplexml_load_string(): p;lt;img src="/UserFiles/FCK/image/prima hangisi(1).jpg" class in /home/alisverispasaji/public_html/system/xml/minikoli/test.php on line 8

PHP Warning:  simplexml_load_string():                                                                                ^ in /home/alisverispasaji/public_html/system/xml/minikoli/test.php on line 8

PHP Fatal error:  Call to a member function children() on boolean in /home/alisverispasaji/public_html/system/xml/minikoli/test.php on line 20

如何解决此错误?

test.php的:

<?php
ini_set('user_agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0) Gecko/20100101 Firefox/9.0');
error_reporting(-1);

function simplexml_load_file_curl($url) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $xml = simplexml_load_string(curl_exec($ch)); // <--- line 8
    return $xml;
}

$url = 'xml link';

$xml = simplexml_load_file_curl($url);

$veri = '<?xml version="1.0" encoding="UTF-8"?>';
$veri .= '
<Urunler>';

foreach($xml->children() as $urun) { // <--- line 20

1 个答案:

答案 0 :(得分:12)

解决问题

查找;

$xml = simplexml_load_string(curl_exec($ch));

改变;

$xml = simplexml_load_string(curl_exec($ch), 'SimpleXMLElement', LIBXML_COMPACT | LIBXML_PARSEHUGE);