tags:

views:

46

answers:

3

Hello,

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:

  • on site, not in textbox
  • without external libraries, frameworks etc.
  • formatted with proper new lines
  • formatted with tabs
  • without colors etc., only text

So how to do it in plain and simple way?

+1  A: 

you can use htmlentities(), htmlspecialchars() or some similar function.

Sinan
+5  A: 

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>'; ?>
Chris Smith
A: 

It should work like that:

echo '<p>This is XML string content:</p>'
echo '<pre>';
echo htmlspecialchars($string);
echo '</pre>';
justastefan