</textarea> tag not not showing up

190 Views Asked by At

I'm trying to make myself a file manager, and I managed to make an "edit file" function in PHP. In the main page I do have a textarea, but when I want to edit the main page "source", the text stops exactly where the textarea tag closes (</textarea>)

Here's a representation of the problem:

<textarea><textarea>Hello World.</textarea></textarea>

The textarea output would be

<textarea><textarea>Hello World.

This is because in the code I've closed the textarea tag, but the browser acts like it's been closed from outside the code.

How can I prevent this?

2

There are 2 best solutions below

1
On BEST ANSWER

You will need to encode the inner tags like so:

<textarea>&lt;textarea&gt;Hello World.&lt;/textarea&gt;</textarea>

In PHP it's simply a matter of running the file source through htmlspecialchars(). A single pass will not alter the output that is displayed in your editor's textarea.

0
On

You should escape characters that make up a tag, if you don't want it to be a tag.

<textarea><textarea>Hello world.&#60/textarea>

Or as BoltClock did, esacpe all special characters.

<textarea>&lt;textarea&gt;Hello World.&lt;/textarea&gt;</textarea>