How to echo XML file in PHP

You can use HTTP URLs as if they were local files, thanks to PHP’s wrappers

You can get the contents from an URL via file_get_contents() and then echo it, or even read it directly using readfile()

$file = file_get_contents('http://example.com/rss');
echo $file;

or

readfile('http://example.com/rss');

Don’t forget to set the correct MIME type before outputing anything, though.

header('Content-type: text/xml');

Leave a Comment