Page 1 of 1
Having HTML code in a Textarea output in PHP
Posted: Thu Aug 17, 2006 8:28 pm
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.
Posted: Thu Aug 17, 2006 8:34 pm
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.
Posted: Thu Aug 17, 2006 8:37 pm
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.
Posted: Thu Aug 17, 2006 8:37 pm
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
Posted: Thu Aug 17, 2006 8:42 pm
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.
Posted: Thu Aug 17, 2006 8:53 pm
by Jordash
Ok, so the update is it works for regular HTML but not scripts like AdSense or something, any ideas out there?
Posted: Thu Aug 17, 2006 9:26 pm
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.
Posted: Fri Aug 18, 2006 4:35 am
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.
Posted: Fri Aug 18, 2006 5:30 am
by SomeOne
how about "htmlspecialchars() " ?
Posted: Fri Aug 18, 2006 12:49 pm
by Jordash
Both of your suggestions worked!
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.