嗨我在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();
?>
Run Code Online (Sandbox Code Playgroud)
在google上搜索之后我发现它与之前的空间有关
我删除空间但没有得到预期的结果.
删除下面的行并尝试错误消息已经消失然后肯定你在settings.php文件中有空格或其他输出的东西.
header("Content-type:text/xml");
Run Code Online (Sandbox Code Playgroud)
检查settings.php文件并删除空格(如果有).请注意,如果settings.php文件还包含其他一些文件,则还必须检查这些文件中的空间.
| 归档时间: |
|
| 查看次数: |
9194 次 |
| 最近记录: |