I have a string with XML:
$string = " <shoes> <shoe> <shouename>Shoue</shouename> </shoe> </shoes> ";
And would like display it on my website like this:
This is XML string content: <shoes> <shoe> <shouename>Shoue</shouename> </shoe> </shoes>
So I would like to do it:
So how to do it in plain and simple way?
Since XML tags are "invented" by the author of the XML document, browsers do not know if a tag like <table> describes an HTML table or a dining table. Without any information about how to display the data, the browsers can just display the XML document as it is. Tip: If you want to style an XML document, use XSLT.
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.
PHP 5's new SimpleXML module makes parsing an XML document, well, simple. It turns an XML document into an object that provides structured access to the XML. To create a SimpleXML object from an XML document stored in a string, pass the string to simplexml_load_string( ). It returns a SimpleXML object.
The PHP simplexml_load_file() function is used to read XML data from a file.
If you just want a plain-text representation of your (pre-formatted) string, you can wrap it in HTML <pre/>
tags and use htmlentities
to escape the angle brackets:
<?PHP echo '<pre>', htmlentities($string), '</pre>'; ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With