Daniel Daniel - 11 days ago 5
HTML Question

Don't process html in value of input

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

<p>Hello!</p>


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
&lt;&gt;


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

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:

<textarea>
<?php /* some code here */ ?> 
</textarea>
Comments