
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
How to 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.
- Related Articles
- How to convert XML file into array in PHP?
- How to display XML in HTML in PHP?
- echo() function in PHP
- How to read the XML file in PowerShell?
- How to get specific nodes in xml file in Python?
- Export Preferences to XML file in Java
- How to create animation using XML file in an Android App?
- How to create Python objects based on an XML file?
- How to add an attribute to the XML file using Powershell?
- Transforming XML file into fixed length flat file in SAP
- How to display errors in PHP file?
- How to import csv file in PHP?
- How to create animation using XML file in an Android App using Kotlin?
- What is a TestNG xml file in TestNG?
- How to delete the specific node from the XML file using PowerShell?

Advertisements