出错 Warning: simplexml_load_file() [function.simplexml-load-file]: a.xml:1: parser warning : xmlParsePITarget: invalid name prefix 'xml' in D:\Program Files\wamp\www\qun\xml\b.php on line 2Warning: simplexml_load_file() [function.simplexml-load-file]: <?xmlversion="1.0"?> in D:\Program Files\wamp\www\qun\xml\b.php on line 2Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in D:\Program Files\wamp\www\qun\xml\b.php on line 2Warning: simplexml_load_file() [function.simplexml-load-file]: a.xml:1: parser error : ParsePI: PI xmlversion space expected in D:\Program Files\wamp\www\qun\xml\b.php on line 2Warning: simplexml_load_file() [function.simplexml-load-file]: <?xmlversion="1.0"?> in D:\Program Files\wamp\www\qun\xml\b.php on line 2Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in D:\Program Files\wamp\www\qun\xml\b.php on line 2Warning: Invalid argument supplied for foreach() in D:\Program Files\wamp\www\qun\xml\b.php on line 3
$str = file_get_contents('a.xml');
//如果不是utf8的编码
//$xml = simplexml_load_string(iconv('gb2312', 'utf-8', $str));
//是utf-8的
$xml = simplexml_load_string($str);
foreach($xml->file as $sfile)
{
echo $sfile->track . "<br/>";
echo $sfile->caption . "<br/>";
echo $sfile->record . "<br/>";
}
Warning: simplexml_load_file() [function.simplexml-load-file]: a.xml:1: parser warning : xmlParsePITarget: invalid name prefix 'xml' in D:\Program Files\wamp\www\qun\xml\b.php on line 2Warning: simplexml_load_file() [function.simplexml-load-file]: <?xmlversion="1.0"?> in D:\Program Files\wamp\www\qun\xml\b.php on line 2Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in D:\Program Files\wamp\www\qun\xml\b.php on line 2Warning: simplexml_load_file() [function.simplexml-load-file]: a.xml:1: parser error : ParsePI: PI xmlversion space expected in D:\Program Files\wamp\www\qun\xml\b.php on line 2Warning: simplexml_load_file() [function.simplexml-load-file]: <?xmlversion="1.0"?> in D:\Program Files\wamp\www\qun\xml\b.php on line 2Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in D:\Program Files\wamp\www\qun\xml\b.php on line 2Warning: Invalid argument supplied for foreach() in D:\Program Files\wamp\www\qun\xml\b.php on line 3
<?xml version="1.0"?>
你要先把xml文件在浏览器上试过才好.
至少xml和vesion之间要有空格
XML文件格式都错了,怎么载入XML文件呢?<?xmlversion="1.0"?>改为<?xml version="1.0"?>