Jump to content

Recommended Posts

Hey,

 

I've got a database that stores HTML mixed with PHP in one of the table cells. It's basically all the content for a particular page; I have a row for each page with all the HTML and PHP code. Anyway, with Daniel0's help I got it working so that both parse correctly (thanks again!!) but the problem comes when I want to simply output the pure code (and NOT parse any of it) to a simple textarea.

 

Here's what happens -- It gets to a certain point in placing the code in the textarea, and then...seems to parse some of the HTML or something? See:

 

outputerror.png

It creates a new textarea, but I just want it to output all the code to the one it's in! :) It's because it's closing the one it's putting the code in, I'm assuming, but how do I fix that?

 

Here's everything after it stops outputting:

 

</textarea></td></tr> 
   <tr><td><textarea name="content" rows="50" cols="50"><?=$qa['content']; ?></textarea></td></tr> 
   <tr><td class="button"><ul><li><a href="#" onclick="document.forms['pageeditor'].submit;"><span>Save changes</span></a></li></ul> 
   </td></tr> 
  </form> 
   <tr><td></td><td></td><td><a href=".....?page=pages&edit=<?=$qa['id'];?>" title="Edit this page's content"></a></td><td></td><td></td></tr> 
</table> 
</p></textarea></td></tr> 
   <tr><td class="button"><ul><li><a href="#" onclick="document.forms['pageeditor'].submit;"><span>Save changes</span></a></li></ul> 
   </td></tr> 
  </form> 
</table> 
</p>

 

This may be more of an HTML question but I'm thinking that in PHP I can somehow stop it from closing the textarea...although...not sure.

 

It seems like I just need to stop it from closing that textarea (which is where it starts outputting what's in the code instead of just showing the source.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/169520-stop-textarea-from-being-closed/
Share on other sites

You're absolutely right and I've realized that since posting this and rereading my code a couple times. It's actually producing everything after that closing of the textarea...which indeed makes perfect sense if it's escaping out of my textarea...bad code  :P

 

So if I need that </textarea> in there (it's part of the code for that particular page) how can I, say, escape it so that it doesn't affect the textarea it's in? I'm thinking I can maybe have all <textarea></textarea> tags replaced with <ta></ta> (and then when I want to code a textarea, just stick in the <ta></ta> tags). That would fix the problem right? I know enough regex to do that :P

 

Thanks!

 

EDIT: @buddyxc - all the input (enough of it to show where the error starts) is in the screenshot ;) See the opening <textarea> tag and then some PHP? after what shows in the screenshot, the rest of the code is below in my original post :) Of course, I can post all of it together if ya want

Use htmlentities when editing the code in the textarea.

<tr><td><textarea name="content" rows="50" cols="50"><?=htmlentities($qa['content'], ENT_QUOTES); ?></textarea></td></tr>

 

When done editing use html_entity_decode, eg

$edited_code = html_entity_decode($_POST['content'], ENT_QUOTES);

Ahhh great suggestion! I'd still love to be able to just edit it like I were a...text file...for example. With html entities I'll have a textarea full of <s and >s. While the textarea stays closed it makes it super hard to edit.

 

I'm looking at throwing this in there - http://javascript.internet.com/snippets/convert-html-entities.html - decodes HTML entities. I'm not sure if it'll close the textarea though, but it seems like if it's just changing the text inside it than it wouldn't right?

 

Thanks for your help

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.