How to display a PHP string "AS IS" (special characters inside)?

This is probably a simple question, but I haven't found an "easy" solution.

I have a PHP string containing exactly these characters:

<code>
<language>
Test string
</language>
<content>for(i&lt;10)</content>
</code>

      

I just want to show this AS IS (char by char) string so I can put it in the textbox. I've tried htmlentities, htmlspecialchar of course, but that's clearly not what I want.

If I use basic "echo", it &lt;

is replaced with '<'. This is problem!

+3


source to share


1 answer


htmlspecialchars

- the right choice, even in textarea

.

<?php echo "<textarea>" . htmlspecialchars($str) . "</textarea>";

      



work.

+2


source







All Articles