I have a string with XML:
$string =
\"
Shoue
\";
<
It should work like that:
echo '<p>This is XML string content:</p>'
echo '<pre>';
echo htmlspecialchars($string);
echo '</pre>';
you can use htmlentities()
, htmlspecialchars()
or some similar function.
If it is a SimpleXMLobject
<pre>
<?php
echo htmlspecialchars(print_r($obj,true));
?>
</pre>
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>'; ?>
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";