How to output XML file in PHP

WBOY
Release: 2023-09-03 17:46:01
forward
875 people have browsed it

How to output XML file in PHP

With the help of PHP wrappers, HTTP URLs can behave like local files. The contents of a URL can be obtained via file_get_contents() and can be echoed. Or read using the readfile function.

Below is sample code to do the same -

$file = file_get_contents('http://example.com/');
echo $file;
Copy after login

An alternative is demonstrated below -

readfile('http://example.com/');
header('Content-type: text/xml'); //The correct MIME type has to be set before displaying the output.
Copy after login

The asXML method can also be used. Below is the sample code -

echo $xml->asXML();
or
$xml->asXML('filename.xml'); //providing a name for the xml file.
Copy after login

The above is the detailed content of How to output XML file in PHP. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!