PHP output XML must be the header of the workaround, phpxmlheader_php tutorial

Source: Internet
Author: User

PHP output XML must be solved by the header, Phpxmlheader


This article explains how PHP output XML must be addressed by the header. Share to everyone for your reference. Here's how:

Problem Description:

Recently, when making an XML output, we found that the XML document that we used to directly use echo input would prompt Error:object # has no method ' load ' error, and then use the header () Output XML header file to resolve it, the following record.

Workaround:

Because the XML long and TXT file is too similar, so I mixed with txt.

Now take a look at the following code:
Copy the code as follows: Echo ' <?xml version= "1.0" encoding= "UTF-8"?>

http://www.bkjia.com/
2013-01-22t11:00:18+08:00

';
Exit
That's a piece of code, anyway. Xml output cannot be validated by XML.
Tip Error Error:object # has no method ' load '
The last half of the day is the same as the files placed directly in 1.xml
The specific code is as follows
Copy the Code code as follows: <?xml version= "1.0" encoding= "UTF-8"?>

http://www.bkjia.com/
2013-01-22t11:00:18+08:00

Just add a header. Tossing for hours ...
The specific code is as follows
Copy the Code code as follows: <?php
Header ("Content-type:text/xml");
Echo ' <?xml version= "1.0" encoding= "UTF-8"?>

http://www.bkjia.com/
2013-01-22t11:00:18+08:00

';
Exit

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


PHP output XML type Text/xml How to enter XML Schema

/*
Write XML file
*/
mysql_connect (' localhost ', ' root ', ');
mysql_query ("Set names UTF8");
mysql_select_db (' 1012javab ');
$result = mysql_query ("SELECT * from goods");
while ($a = MYSQL_FETCH_ASSOC ($result)) {
$arr [] = $a;
}

Instantiate a DOM object
$doc = new DOMDocument;
Format input
$doc->formatoutput = true;

Create a root node
$books = $doc->createelement (' books ');
adding ELEMENT nodes
$books = $doc->appendchild ($books);
/*
$books = $doc->appendchild ($books);
$book = $doc->createelement (' book ');
$books->appendchild ($book);
$title = $doc->createelement (' TTT ');
$book->appendchild ($title);
*/
foreach ($arr as $key = = $val) {
Echo 11;
$book = $doc->createelement (' book ');
foreach ($val as $key 1=> $val 1) {

########################## #第一组
$title = $doc->createelement ($key 1);
Create a file node
$content = $doc->createtextnode ($val 1);
$title->appendchild ($content);
$book->appendchild ($title);
}
$books->appendchild ($book);
}

if ($doc->save (' Goods.xml ')) {
echo ' yes ';
}else{
Echo ' no ';
}

/*
$doc = new DOMDocument (' 1.0 ');
We want a nice output
$doc->formatoutput = true;

$root = $doc->createelement (' book ');
$root = $doc->appendchild ($root);

$title = $doc->createelement (' title ');
$title ... Remaining full text >>

PHP file output Xml,ie only show value no element name

Normal phenomenon, the new version of the browser should have this automatic parsing function, this is the standard.
It's good to view the source files yourself.

http://www.bkjia.com/PHPjc/895112.html www.bkjia.com true http://www.bkjia.com/PHPjc/895112.html techarticle PHP output XML must be a solution to the header, Phpxmlheader This example describes the PHP output XML must be the header of the solution. Share to everyone for your reference. Here's how it works: Problem description ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.