您好,我正在 php 中生成 xml 文件,但出现错误
XML 解析错误:XML 或文本声明不在实体的开头
我的代码是——
<?php require_once('../../settings.php');
header("Content-type:text/xml");
$dom=new DOMDocument('1.0');
$dom->formatOutput = true;
$id=(int)$_GET['imageid'];
$query="select * from tbl_image_gallery where imageId='$id' ORDER BY gallId DESC ";
$select=mysql_query($query);
$content = $dom->appendChild($dom->createElement('content'));
while($res=mysql_fetch_array($select))
{
$image = $content->appendChild($dom->createElement('image'));
$small_image_path = $image->appendChild($dom->createElement('small_image_path'));
$small_image_path->appendChild($dom->createTextNode("image_gallery/load/images/small/".$res['image']));
$big_image_path = $image->appendChild($dom->createElement('big_image_path'));
$big_image_path->appendChild($dom->createTextNode("image_gallery/load/images/big/".$res['image']));
$description = $image->appendChild($dom->createElement('description'));
$description->appendChild($dom->createCDATASection($res['description']));
}
echo $test1 = $dom->saveXML();
?>
在google上搜索后发现之前是与空间有关的问题
我删除了空间但没有得到预期的结果。
删除下面的行并尝试如果错误消息消失了那么肯定您在之前输出了空格或其他内容settings.php
file.
header("Content-type:text/xml");
检查 settings.php 文件并删除空格(如果有)。请注意,如果 settings.php 文件还包含一些其他文件,您还必须检查这些文件中的空间。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)