Daniel Daniel - 14 days ago 7
HTML Question

Dont process html in value of input

I have a entry in my mysql table that contains html code (<p>Hello!</p>)
This show up fine when I want to display it (echo $entry) but when I place echo $entry in a textarea value= it executes the code instead of showing it.
Is there any way to stop the code 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>

Thanks,

Daniel

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>