![]() |
|
#1
|
|||
|
|||
working with html HELPI'm trying to wrap my head around working with html text but I cannot grasp how it all works. Ok so I in the following code I have entered the contents of a html doc into an array and been experimenting with the different functions.
PHP Code:
If I now have converted all html characters to their entity reference values it displays the html correctly so as not to be executed in a textarea. So now If I edit the html in the textarea using normal html characters (quotes etc) will the data be converted when I send the data? And how would I convert the character entities back to their original html characters? I'm sure theirs a function that does this. Thanx in advance peace |
|
#2
|
|||
|
|||
|
Great I found a resource that deals with this nicely!
za2.php.net showed how to use html_entity_decode, that function name I was missing. What is confusing me now is how the html text is collected and dealt with from a form element, ie a textarea field. So heres the situation: a user enters html text into a textarea, including quotes and things similar, and that info is sent as a text string right? The info would need to be edited before being sent right? Like \ needs to be placed before the quotes so that php can store the html text in a varaible. So i donno how to do this. Can anyone please help me? Or does anyone know where I could find examples of what I am trying to do here (work with html text from a form) it would be a huge help i'm really struggling with this. peace |
|
#3
|
|||
|
|||
|
Well, I seem to have solved it. Why did no one say that html text was formatted (addslashes) as it is sent?
It was pretty easy to figure it out at the end of the day. All I had to do www.spliffsa.com Go ahead try it and view the html source of the results page. There's those sneaky backslashes that confused the hell outa me. And the php is PHP Code:
|
|
#4
|
||||
|
||||
|
Quote:
Quote:
__________________
Age is unimportant -- except in cheese |
|
#5
|
|||
|
|||
|
Well i'm sure has something to do with the "magic_quotes" or sommin similar setup withing the php.ini file?
Cos on one linux server it automatically adds slashes, yet on a different linux server it doesn't. So I do this to convert line breaks and deal with quotes: nl2br(addslashes($textvalue)) It's all coming together now... peace |
|
#6
|
||||
|
||||
|
I realise that I may be too late but I'll add my comments nevertheless:
I don't know why you would create a CUSTOM function to do what is already available in PHP. For example, I would re-write the example code in your first post like this... PHP Code:
Quote:
You don't need to do anything in this situation - trust me! For example if you view the source code of your <textarea> and if it looks like this: HTML Code:
and if you then submit this form, the receiving script has this string in the $_POST['some'] variable : <span>Something</span>. Strange but true...! About magic_quotes_gpc, it's a setting inside php.ini file and if it's ON, all GET / POST / COOKIE operations & variables are escaped for (quotes, backslashes and NULs) automatically. There are opinions about this setting and many cool ideas to make your scripts deal with either situation without modifying your code. Here's just one, I wrote a LONG time ago: http://www.gidforums.com/t-380.html. __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#7
|
|||
|
|||
|
thanx for the help JdS
Quote:
Yes I see this now...its kinda hard to grasp how a variable (eg some) can contain html elements, like quotes, but understanding that makes this a whole lot easier. Like even with the html being encoded it'll send it decoded (as you mentioned). I realise more and more the easiest way to learn code is through trial and error. It's been a while since my turbo pascal days! My main point to learning this is to simply display all the html text from a html file in a textarea. (So there really is no need to encode the text.) And then to save the contents of the textarea into the same html file. After learning how to encode and decode I realise I don't really need to do it! Last thing I need to ask is about the _POST variables. I've realised now you work with your form variables different to what i've taught myself. Like instead of using $_POST['some'] I would just use $some. What exactly is the difference? thanx a lot for the help peace, rich |
|
#8
|
|||
|
|||
|
here u go
http://hk.php.net/manual/en/language.variables.external.php __________________
http://www.cdhouse.biz Cheap Linux, FreeBSD, OpenOffice CDs |
|
#9
|
||||
|
||||
|
To quickly answer your question about using $_POST['some'] instead of $some, I will just quote something found on the page that cdhouse.biz has linked to in his reply:
Quote:
__________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#10
|
|||
|
|||
|
so its better to use instead $some instead of $_POST['some']?
|
Recent GIDBlog
Developing GUIs with wxPython (Part 3) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What should I use? XHTML 1.0 or HTML 4.01 Strict? | retxedz | Web Design Forum | 0 | 24-Dec-2004 15:56 |
| how do i make it so the image around my html slice expands when typed in ? | gameshow863 | Web Design Forum | 6 | 03-Jun-2004 05:48 |
| Getting HTML Source with PHP | Optical | MySQL / PHP Forum | 2 | 18-May-2004 16:57 |
| html to php | tenaki | Web Design Forum | 17 | 28-Oct-2003 16:18 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The