Jump to content

PHP </textarea> in a textarea.


Speedysnail6

Recommended Posts

Hi. I don't know how to have the code </textarea> INSIDE of a textarea using PHP.

$edit_content_de = "<textarea>Text</textarea>asd";     
<p><?php echo '<textarea name="content" id="codeTextarea" style="width:90%; height:500px;">'. $edit_content_de; .'</textarea>'; ?></p>

But obviously what happens is the textarea ends and BELOW the textarea it says "asd". How do I stop this and have it say </textarea> INSIDE textarea instead of closing it?

Edited by Speedysnail6
Link to comment
Share on other sites

all text content (anything that isn't html/javascript/css) should be passed through htmlentities() before being output on a web page, so that any html entities in it are converted to their character equivalents.

 

when these are submitted, they will be converted back to the actual html entities.

Link to comment
Share on other sites

So you want to have the literal words in there? Use the html characters instead

<?php $edit_content_de = "<textarea>Text</textarea>asd"; ?>
<p><?php echo '<textarea name="content" id="codeTextarea" style="width:90%; height:500px;">'.$edit_content_de.'</textarea>'; ?></p>
Edited by JD*
Link to comment
Share on other sites

A couple things:

 

1. No need to put your hard coded textarea tags int he echo

2. As mac_gyver and mentalist stated above, you should use htmlentities instead of trying to figure out the conversions yourself.

<?php
$edit_content_de = "<textarea>Text</textarea>asd";     
?>
<p><textarea name="content" id="codeTextarea" style="width:90%; height:500px;"><?php echo htmlentities($edit_content_de); ?></textarea></p>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.