Daniel Daniel - 1 year ago 66
HTML Question

Don't process html in value of input

I have an entry in my mysql table that contains html code:


This shows up fine when I want to display it
echo $entry

but when I place
echo $entry
in a textarea's value, it executes the code instead of showing it.
Is there any way to stop the code from executing and show the tags or convert to and from

Here is the code:

echo "<label for=\"details\">Details:</label><textarea id=\"details\" cols=\"60\" rows=\"10\" name=\"details\" value=\"" . $row["details"]."\"></textarea>";

Here is the entry:

<p><ol><li>HKCU/Software/Microsoft/Windows/NT/CurrentVersion/WindowsLegacy/DefaultPrinterMode<li> Set to 0 (on)</ol>

Answer Source

You have to escape special characters. You can do that with htmlspecialchars().

What's more, You should not set a value to the textarea but rather write it in its content:

<?php /* some code here */ ?> 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download