Solution that php output xml must header

  • 2021-07-22 09:09:08
  • OfStack

In this paper, an example is given to describe the solution that php must output xml to header. Share it for your reference. The specific methods are as follows:

Problem description:

Recently, when doing an xml output, we found that the xml document that we directly use echo input will prompt Error: Object # has no method 'load' error, and then we changed to header () output xml header file to solve it. Record 1 below.

Solution:

Because the xml and txt files are too long and similar, so I am mixed up with txt.

Let's take a look at the following code:

echo '<?xml version="1.0" encoding="UTF-8"?>
<sitemap>
<loc>https://www.ofstack.com/</loc>
<lastmod>2013-01-22T11:00:18+08:00</lastmod>
</sitemap>
';
exit;

Is such a piece of code, xml output alive and dead can not pass xml verification.
Error Prompt Error: Object # has no method 'load'
Finally, I checked the file 1 directly placed in 1. xml for half a day
The specific code is as follows
<?xml version="1.0" encoding="UTF-8"?>
<sitemap>
<loc>https://www.ofstack.com/</loc>
<lastmod>2013-01-22T11:00:18+08:00</lastmod>
</sitemap>

Just add an header. For hours. . . . .
The specific code is as follows
<?php
header("Content-type:text/xml");
echo '<?xml version="1.0" encoding="UTF-8"?>
<sitemap>
<loc>https://www.ofstack.com/</loc>
<lastmod>2013-01-22T11:00:18+08:00</lastmod>
</sitemap>
';
exit;

I hope this article is helpful to everyone's php programming.


Related articles: