Home > Backend Development > PHP Tutorial > Detailed explanation of 3 methods for PHP to output XML to the page_PHP Tutorial

Detailed explanation of 3 methods for PHP to output XML to the page_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:08:37
Original
861 people have browsed it

The first method:

Copy the code The code is as follows:

header("Content-type: text/xml");
echo "";
echo "";
echo "";
echo "";
echo "Little Rookie";
echo "
" ;
echo "";
echo "24";
echo "
";
echo "";
echo "Male" ;
echo "
";
echo "
";
echo "";
echo "";
echo "Yanyan";
echo "
";
echo "";
echo "23";
echo "
";
echo "";
echo "female";
echo "
";
echo "
";
echo "";
?>

Second method:
Copy code The code is as follows:

header("Content-type: text/xml");
echo "";
echo "Little Rookie24 MaleYanyan23Female ";
?>

Third method:
Copy code The code is as follows:

/*
Use PHP’s DOM control to create XML output
Set the output content type to xml
* /
header('Content-Type: text/xml;');
//Create a new xml file
$dom = new DOMDocument('1.0', 'utf-8');

//Create element
$response = $dom->createElement('response');
$dom->appendChild($response);

//Create the element and make it a child element of
$books = $dom->createElement('books');
$response->appendChild( $books);

//Create a title for the book
$title = $dom->createElement('title');
$titleText = $dom->createTextNode('PHP and AJAX');
$title->appendChild($titleText);

//Create isbn element for book
$isbn = $dom->createElement('isbn');
$isbnText = $dom->createTextNode('1-21258986');
$isbn->appendChild($isbnText);

//Create book element
$book = $dom->createElement('book');
$book->appendChild($title);
$book->appendChild( $isbn);

//Regard as child element
$books->appendChild($book);

//Create an XML structure in a string variable
$xmlString = $dom->saveXML();

//Output XML string
echo $xmlString;

?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327454.htmlTechArticleFirst method: Copy the code as follows: ?php header("Content-type: text/xml") ; echo "?xml version=/"1.0/" encoding=/"UTF-8/"?"; echo "users"; echo "user"; echo "name"; echo "小...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template