Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There are a couple of ways to showcase HTML string (with HTML tags) as text inside a textarea:

  1. Escape HTML tags: You can escape the HTML tags using the HTML entities. For example, < becomes < and > becomes >. Then set the escaped HTML string as the value of textarea. This will display the HTML string as plain text inside the textarea.

  2. Wrap inside tag: You can wrap the HTML string inside the <code> tag and set it as the value of textarea. This will display the HTML string as formatted text inside the textarea.

Here's an example using the first method:

<textarea><?php echo htmlentities($htmlString) ?></textarea>

And here's an example using the second method:

<textarea><code><?php echo $htmlString ?></code></textarea>