How to print an XML file to the screen in PHP? Show This is not working:
Is there a simple solution? Maybe without SimpleXML?
Syscall 18.3k10 gold badges33 silver badges49 bronze badges asked Jul 29, 2009 at 11:33
1 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()
or
Don't forget to set the correct MIME type before outputing anything, though.
answered Jul 29, 2009 at 11:40
Josh DavisJosh Davis 27.9k5 gold badges51 silver badges67 bronze badges 1 Here's what worked for me:
Using htmlspecialchars will prevent tags from being displayed as html and won't break anything. Note that I'm using Prettyprint to highlight the code ;) answered Aug 7, 2012 at 13:46
GabLeRouxGabLeRoux 15.4k13 gold badges61 silver badges78 bronze badges 0 You can use the asXML method
You can also give it a filename
answered Jul 29, 2009 at 11:57
Cristian TomaCristian Toma 5,6332 gold badges35 silver badges42 bronze badges 1 This worked for me:
Kevin Panko 8,14919 gold badges51 silver badges60 bronze badges answered Apr 22, 2015 at 19:07
jimjim 2124 silver badges10 bronze badges 1 If you just want to print the raw XML you don't need Simple XML. I added some error handling and a simple example of how you might want to use SimpleXML.
answered Jul 29, 2009 at 12:14
Tom HaighTom Haigh 56.6k20 gold badges112 silver badges140 bronze badges Am I oversimplifying this?
Some places (like digg.com) won't allow you to access their site without having a user-agent, in which case you would need to set that with ini_set() prior to running the file_get_contents(). answered Jul 29, 2009 at 11:39
SampsonSampson 261k74 gold badges530 silver badges559 bronze badges 0 To display the html/xml "as is" (i.e. all entities and elements), simply escape the characters <, &, and enclose the result with <pre>:
Prints:
Tested on Chrome 45 answered Sep 16, 2015 at 14:41
miklmikl 1,0071 gold badge18 silver badges31 bronze badges 1 If anyone is targeting yahoo rss feed may benefit from this snippet
You may want to run it in your browser first to see what is there and before looping and style it up pretty simple To grab the first item description
You can see a demo here answered Apr 18, 2016 at 11:08
ShapCyberShapCyber 3,1302 gold badges20 silver badges25 bronze badges This works:
answered Aug 13, 2018 at 8:26
NullNull 8369 silver badges12 bronze badges The best solution is to add to your apache
and then simply having a file The file
it works :) answered Jan 11, 2020 at 7:20
How do I print an XML file?Browse for the XML file by clicking File->Open or pressing Ctrl+O. Click File->Print or press Ctrl+P to open the Printer window.
How display XML file in browser using PHP?php header("Content-type: text/xml"); $yourFile = "xmlfile. xml"; $file = file_get_contents($yourFile); echo $file; If you insist on simple xml you can write like this.
How do you read and write XML document with PHP?Start with $videos = simplexml_load_file('videos. xml'); You can modify video object as described in SimpleXMLElement documentation, and then write it back to XML file using file_put_contents('videos. xml', $videos->asXML()); Don't worry, SimpleXMLElement is in each PHP by default.
HOW include XML file in PHP?Example. $xml=simplexml_load_file("note. xml"); print_r($xml);
|