php - XML 解析错误 : XML or text declaration not at start of entity in php

标签 php

您好,我正在用 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 文件中有空间或其他输出。

  header("Content-type:text/xml");

检查 settings.php 文件并删除空格(如果有)。请注意,如果 settings.php 文件还包含一些其他文件,您还必须检查这些文件中的空间。

关于php - XML 解析错误 : XML or text declaration not at start of entity in php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5387514/

相关文章:

PHP MYSQL调用多个存储过程时出错

php - FPDF拒绝通过继承合作

php - 根据查询类型和表将流量路由到特定的 MySQL 连接

php - 什么更有效率?大量 SQL 查询或循环遍历它们?

php - 从 iPhone sdk 上的 Cocoa Touch 发送变量到 php

php - 如何仅删除子目录下页面的 .php 扩展名?

php - 关于重复键更新语法 php/mysql 错误

php - 如何在 Laravel 中检索当前日期的数据

php - 使用 PHP 和 MySQL 生成 JSON 格式的表

Phpmyadmin 和 mysql 显示错误结果