Having HTML code in a Textarea output in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jordash
Forum Newbie
Posts: 6
Joined: Thu Aug 17, 2006 7:36 pm

Having HTML code in a Textarea output in PHP

Post by Jordash »

Alright so here is basically what I am trying to do, I have a textarea like so:

Code: Select all

<textarea name="whatever" value="">blah blah blah</textarea>
Now say that text area takes HTML code like so:

Code: Select all

<textarea name="whatever" value=""><p/>text<b class="something">blah<br/></textarea>
Now in PHP I want it to output the HTML code in the textarea but output it as if it was actual HTML i.e. Here is what i've tried:

Code: Select all

<?php
echo $whatever;  // print out the HTML in the text area
?>
If we take the text area code above it should print out:

text
blah (bolded)

However it doesn't print out anything, Any ideas or ways to print out HTML from a text area in PHP.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Let me get this straight. You want to be able to edit the text, have it styled by html, but not see the html code? You're looking for a WYSIWYG editor such as TinyMCE or Fckeditor.
Jordash
Forum Newbie
Posts: 6
Joined: Thu Aug 17, 2006 7:36 pm

Post by Jordash »

I'm not really looking for an editor i'm actually writing an extension for a PHP CMS (Joomla) so essentially I am trying to write a very basic editor, that just outputs the HTML in a textarea out in PHP.
matt1019
Forum Contributor
Posts: 172
Joined: Thu Jul 06, 2006 6:41 pm

Post by matt1019 »

another alternative is to use one of those AJAX forum widgets....

DOJO, i saw, had a very good form widget ---> editor

http://www.dojotoolkit.com/

-Matt
Jordash
Forum Newbie
Posts: 6
Joined: Thu Aug 17, 2006 7:36 pm

Post by Jordash »

Actually to clarify, i'm putting AdSense into the TextArea.

i.e.

Code: Select all

<textarea>
ADSENSE CODE HERE
</textarea>
And it isn't working, it appears to work with regular HTML very strange.
Jordash
Forum Newbie
Posts: 6
Joined: Thu Aug 17, 2006 7:36 pm

Post by Jordash »

Ok, so the update is it works for regular HTML but not scripts like AdSense or something, any ideas out there?
Jordash
Forum Newbie
Posts: 6
Joined: Thu Aug 17, 2006 7:36 pm

Post by Jordash »

ok, I think I found a workaround but if anyone knows an answer to my first question, be sure to let me know.

Thanks for all the help.
korto
Forum Commoner
Posts: 36
Joined: Thu Aug 18, 2005 6:30 am
Location: Greece
Contact:

Post by korto »

You might consider using javascript and the innerHTML property. Assign a specific id to your textarea and then with javascript find your textarea by the id ( getElementById() ) and assign its innerHTML value to a php variable that you can later print or echo.
User avatar
SomeOne
Forum Commoner
Posts: 27
Joined: Tue Jul 25, 2006 2:06 am

Post by SomeOne »

how about "htmlspecialchars() " ?
Jordash
Forum Newbie
Posts: 6
Joined: Thu Aug 17, 2006 7:36 pm

Post by Jordash »

Both of your suggestions worked! :D

but I found an easier way, I was able to provide the input for the different areas of AdSense, color, text color, background, size etc.. through text fields, and it worked!

Thanks for all the help.
Post Reply