php 错误:XML 或文本声明不在实体源的开头

发布于 2024-12-16 19:12:27 字数 7425 浏览 0 评论 0原文

每当我在 PHP 文件中使用以下代码时,它都会给我错误(错误:XML 或文本声明不在实体的开头 来源)

<?xml version='1.0' encoding='utf-8'?>

我不知道解决方案是什么,

请帮忙

提前致谢

<?xml version='1.0' encoding='utf-8'?><rows><page>1</page><records>15</records><total>1</total><row id='18'><cell>18</cell><cell>2011-9-13</cell><cell>AL</cell><cell>2011-10-19</cell><cell>2011-10-21</cell><cell>3</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell>mohan</cell><cell>Davinder Singh</cell></row><row id='17'><cell>17</cell><cell>2011-5-25</cell><cell>SL</cell><cell>2011-5-19</cell><cell>2011-5-19</cell><cell>1</cell><cell></cell><cell></cell><cell>Approved</cell><cell>Davinder</cell><cell>Kavita y</cell></row><row id='16'><cell>16</cell><cell>2011-5-25</cell><cell>SL</cell><cell>2011-5-24</cell><cell>2011-5-24</cell><cell>1</cell><cell></cell><cell></cell><cell>Approved</cell><cell></cell><cell>Kavita y</cell></row><row id='15'><cell>15</cell><cell>2011-5-26</cell><cell>AL</cell><cell>2011-7-08</cell><cell>2011-7-12</cell><cell>0</cell><cell></cell><cell></cell><cell>Disapproved</cell><cell></cell><cell>Kavita y</cell></row><row id='14'><cell>14</cell><cell>2011-5-25</cell><cell>AL</cell><cell>2011-6-30</cell><cell>2011-7-02</cell><cell>3</cell><cell></cell><cell></cell><cell>Approved</cell><cell></cell><cell>Kavita y</cell></row><row id='13'><cell>13</cell><cell>2011-9-14</cell><cell>CL</cell><cell>2011-6-15</cell><cell>2011-6-15</cell><cell>1</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell></cell><cell>Kavita y</cell></row><row id='12'><cell>12</cell><cell>2011-5-25</cell><cell>CL</cell><cell>2011-6-10</cell><cell>2011-6-12</cell><cell>3</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell></cell><cell>Kavita y</cell></row><row id='11'><cell>11</cell><cell>2011-5-25</cell><cell>SL</cell><cell>2011-5-20</cell><cell>2011-5-17</cell><cell>4</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell></cell><cell>Kavita y</cell></row><row id='10'><cell>10</cell><cell>2011-5-25</cell><cell>CL</cell><cell>2011-6-03</cell><cell>2011-6-05</cell><cell>3</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell>mohan</cell><cell>Davinder Singh</cell></row><row id='9'><cell>9</cell><cell>2011-5-26</cell><cell>SL</cell><cell>2011-5-18</cell><cell>2011-5-22</cell><cell>5</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell>mohan</cell><cell>Davinder Singh</cell></row><row id='8'><cell>8</cell><cell>2011-5-24</cell><cell>AL</cell><cell>2011-5-20</cell><cell>2011-5-20</cell><cell>0</cell><cell></cell><cell></cell><cell>Disapproved</cell><cell>mohan</cell><cell>Davinder Singh</cell></row><row id='7'><cell>7</cell><cell>2011-5-24</cell><cell>CL</cell><cell>2011-5-20</cell><cell>2011-5-20</cell><cell>1</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell>mohan</cell><cell>Davinder Singh</cell></row><row id='4'><cell>4</cell><cell>2011-9-14</cell><cell>SL</cell><cell>2011-5-20</cell><cell>2011-5-20</cell><cell>1</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell>mohan</cell><cell>Davinder Singh</cell></row><row id='3'><cell>3</cell><cell>2011-5-24</cell><cell>SL</cell><cell>2011-5-20</cell><cell>2011-5-20</cell><cell>1</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell>mohan</cell><cell>Davinder Singh</cell></row><row id='1'><cell>1</cell><cell>2011-5-24</cell><cell>SL</cell><cell>2011-5-20</cell><cell>2011-5-22</cell><cell>0</cell><cell>dd</cell><cell>remarks</cell><cell>Disapproved</cell><cell>mohan</cell><cell>Davinder Singh</cell></row></rows>

和 php 代码

header("Content-type: text/xml;charset=utf-8");

$s = "<?xml version='1.0' encoding='utf-8'?>";
$s .=  "<rows>";
$s .= "<page>".$page."</page>";
$s .= "<records>".$count."</records>";

$s .= "<total>".$total_pages."</total>";


// be sure to put text data in CDATA
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {


    $s .= "<row id='". $row['fld_id']."'>";

    $s .= "<cell>". $row['fld_id']."</cell>";   
    $s .= "<cell><![CDATA[". getDepartmentName($row['deptSr'])."]]></cell>";
    $s .= "<cell>". $row['email']."</cell>";
    $s .= "<cell>". $row['fname']."</cell>";
    $s .= "<cell>". $row['lname']."</cell>";
    $s .= "<cell>". $row['password']."</cell>";

    $s .= "<cell>". listlevel($row['level'])."</cell>"; 
    $s .= "<cell>". date('Y-m-d G:i:s', $row['date_create'])."</cell>";
    $s .= "<cell>". date('Y-m-d G:i:s', $row['last_login'])."</cell>";  
    $s .= "<cell>". $row['ip_addr']."</cell>";
    $s .= "<cell>". $row['dob']."</cell>";  
    $s .= "<cell>". $row['street']."</cell>";       
    $s .= "<cell>". $row['phone_mob']."</cell>";        
    $s .= "<cell>". $row['phone_home']."</cell>";   
    $s .= "<cell>". liststatus($row['fld_enabled'])."</cell>";  

    $s .= "</row>";
}
$s .= "</rows>"; 

echo $s;

whenever I use the following code in PHP files , it gives me the error (Error: XML or text declaration not at start of entity
Source)

<?xml version='1.0' encoding='utf-8'?>

I don't know what could be the solution

please help

Thanks in advance

<?xml version='1.0' encoding='utf-8'?><rows><page>1</page><records>15</records><total>1</total><row id='18'><cell>18</cell><cell>2011-9-13</cell><cell>AL</cell><cell>2011-10-19</cell><cell>2011-10-21</cell><cell>3</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell>mohan</cell><cell>Davinder Singh</cell></row><row id='17'><cell>17</cell><cell>2011-5-25</cell><cell>SL</cell><cell>2011-5-19</cell><cell>2011-5-19</cell><cell>1</cell><cell></cell><cell></cell><cell>Approved</cell><cell>Davinder</cell><cell>Kavita y</cell></row><row id='16'><cell>16</cell><cell>2011-5-25</cell><cell>SL</cell><cell>2011-5-24</cell><cell>2011-5-24</cell><cell>1</cell><cell></cell><cell></cell><cell>Approved</cell><cell></cell><cell>Kavita y</cell></row><row id='15'><cell>15</cell><cell>2011-5-26</cell><cell>AL</cell><cell>2011-7-08</cell><cell>2011-7-12</cell><cell>0</cell><cell></cell><cell></cell><cell>Disapproved</cell><cell></cell><cell>Kavita y</cell></row><row id='14'><cell>14</cell><cell>2011-5-25</cell><cell>AL</cell><cell>2011-6-30</cell><cell>2011-7-02</cell><cell>3</cell><cell></cell><cell></cell><cell>Approved</cell><cell></cell><cell>Kavita y</cell></row><row id='13'><cell>13</cell><cell>2011-9-14</cell><cell>CL</cell><cell>2011-6-15</cell><cell>2011-6-15</cell><cell>1</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell></cell><cell>Kavita y</cell></row><row id='12'><cell>12</cell><cell>2011-5-25</cell><cell>CL</cell><cell>2011-6-10</cell><cell>2011-6-12</cell><cell>3</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell></cell><cell>Kavita y</cell></row><row id='11'><cell>11</cell><cell>2011-5-25</cell><cell>SL</cell><cell>2011-5-20</cell><cell>2011-5-17</cell><cell>4</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell></cell><cell>Kavita y</cell></row><row id='10'><cell>10</cell><cell>2011-5-25</cell><cell>CL</cell><cell>2011-6-03</cell><cell>2011-6-05</cell><cell>3</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell>mohan</cell><cell>Davinder Singh</cell></row><row id='9'><cell>9</cell><cell>2011-5-26</cell><cell>SL</cell><cell>2011-5-18</cell><cell>2011-5-22</cell><cell>5</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell>mohan</cell><cell>Davinder Singh</cell></row><row id='8'><cell>8</cell><cell>2011-5-24</cell><cell>AL</cell><cell>2011-5-20</cell><cell>2011-5-20</cell><cell>0</cell><cell></cell><cell></cell><cell>Disapproved</cell><cell>mohan</cell><cell>Davinder Singh</cell></row><row id='7'><cell>7</cell><cell>2011-5-24</cell><cell>CL</cell><cell>2011-5-20</cell><cell>2011-5-20</cell><cell>1</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell>mohan</cell><cell>Davinder Singh</cell></row><row id='4'><cell>4</cell><cell>2011-9-14</cell><cell>SL</cell><cell>2011-5-20</cell><cell>2011-5-20</cell><cell>1</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell>mohan</cell><cell>Davinder Singh</cell></row><row id='3'><cell>3</cell><cell>2011-5-24</cell><cell>SL</cell><cell>2011-5-20</cell><cell>2011-5-20</cell><cell>1</cell><cell></cell><cell></cell><cell>Waiting for approval</cell><cell>mohan</cell><cell>Davinder Singh</cell></row><row id='1'><cell>1</cell><cell>2011-5-24</cell><cell>SL</cell><cell>2011-5-20</cell><cell>2011-5-22</cell><cell>0</cell><cell>dd</cell><cell>remarks</cell><cell>Disapproved</cell><cell>mohan</cell><cell>Davinder Singh</cell></row></rows>

and the php code

header("Content-type: text/xml;charset=utf-8");

$s = "<?xml version='1.0' encoding='utf-8'?>";
$s .=  "<rows>";
$s .= "<page>".$page."</page>";
$s .= "<records>".$count."</records>";

$s .= "<total>".$total_pages."</total>";


// be sure to put text data in CDATA
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {


    $s .= "<row id='". $row['fld_id']."'>";

    $s .= "<cell>". $row['fld_id']."</cell>";   
    $s .= "<cell><![CDATA[". getDepartmentName($row['deptSr'])."]]></cell>";
    $s .= "<cell>". $row['email']."</cell>";
    $s .= "<cell>". $row['fname']."</cell>";
    $s .= "<cell>". $row['lname']."</cell>";
    $s .= "<cell>". $row['password']."</cell>";

    $s .= "<cell>". listlevel($row['level'])."</cell>"; 
    $s .= "<cell>". date('Y-m-d G:i:s', $row['date_create'])."</cell>";
    $s .= "<cell>". date('Y-m-d G:i:s', $row['last_login'])."</cell>";  
    $s .= "<cell>". $row['ip_addr']."</cell>";
    $s .= "<cell>". $row['dob']."</cell>";  
    $s .= "<cell>". $row['street']."</cell>";       
    $s .= "<cell>". $row['phone_mob']."</cell>";        
    $s .= "<cell>". $row['phone_home']."</cell>";   
    $s .= "<cell>". liststatus($row['fld_enabled'])."</cell>";  

    $s .= "</row>";
}
$s .= "</rows>"; 

echo $s;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我早已燃尽 2024-12-23 19:12:27

XML 或文本声明不在实体的开头表示序言不是输出中的第一行。最有可能的是,空行以某种方式进入了您的输出。这个错误并不是 WordPress 独有的。然而,正如我在评论中提到的,我在 Google 上搜索了错误消息,并且 WordPress 出现在很多结果中。如果您不使用 WordPress,请忽略此答案的其余部分。

免责声明:我对 WordPress 一无所知,所以我不愿意以这种身份回答;然而,由于在撰写本文时还没有其他答案,我将简单地向您展示我在该主题上发现的内容。

如果您使用 WordPress,通过在问题中添加 WordPress 标签可能会吸引更好的答案。虽然不能保证,但它可能会引起那些比我更有知识的人的注意。

XML or text declaration not at start of entity indicates that the prolog isn’t the first line in the output. Most likely, a blank line is somehow finding its way into your output. This error isn’t unique to WordPress; however, as I mentioned in my comment, I did a search for the error message on Google and WordPress comes up in a lot of the results. If you’re not using WordPress, kindly disregard the remainder of this answer.

Disclaimer: I know nothing about WordPress so I’m reluctant to answer in that capacity; however, since there are no other answers as of this writing, I’ll simply show you what I’ve found on the subject.

If you are using WordPress, you may attract better answers by adding the WordPress tag to your question. There’s no guarantee, but it could draw the attention of those more knowledgeable than myself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文