Reputation: 26089
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?
Upvotes: 33
Views: 76303
Reputation: 23
I searched for a solution to have slightly coloured output:
$escaped = htmlentities($content);
$formatted = str_replace('<', '<span style="color:blue"><', $escaped);
$formatted = str_replace('>', '></span>', $formatted);
echo "<pre>$formatted</pre>\n";
Upvotes: 1
Reputation: 2190
If it is a SimpleXMLobject
<pre>
<?php
echo htmlspecialchars(print_r($obj,true));
?>
</pre>
Upvotes: 1
Reputation: 595
It should work like that:
echo '<p>This is XML string content:</p>'
echo '<pre>';
echo htmlspecialchars($string);
echo '</pre>';
Upvotes: 6
Reputation: 10435
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>'; ?>
Upvotes: 67
Reputation: 5980
you can use htmlentities()
, htmlspecialchars()
or some similar function.
Upvotes: 6