
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Echo XML File in PHP
HTTP URLs can be used to behave like local files, with the help of PHP wrappers. The contents from a URL can be fetched through the file_get_contents() and it can be echoed. or read using the readfile function.
Below is a sample code to do the same −
$file = file_get_contents('http://example.com/'); echo $file;
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.
The asXML method also can be used. Below is a sample code −
echo $xml->asXML(); or $xml->asXML('filename.xml'); //providing a name for the xml file.
Advertisements