Entry
I store "\" as a hidden data and upon submitting the form, on the receivng php page shows up as "\\". Why is this so ?
Mar 15th, 2000 12:26
Matt Gregory, Knowledge Based, Ben Udall,
In languages like PHP, Perl, Python, and C++ (All close to the standard
origional c syntax) the character \ is considered an escape character
when entered into the code in a string. Escape characters are used to
tell the compiler that what you are typing should be interpreted as a
literal value instead of the actual character.
For example, if you want to put a carage return and line feed at the
end of a string being sent over the network as a standard TCP/IP
packet, you will need your string to look like this:
"This is the string I'm sending, and at the end is a <CR><LF>\r\n"
That tells the compiler to change \r to a cariage return and the \n to
a line feed.
When PHP sees a \ value in a text box, it assumes that you mean a
literal backslash, not an escape character (because it looks at it as
though it's been typed by an end-user). In order to keep it from
causing a problem, it adds a double slash, which tells the interpreter
to make it a literal backslash.
Solution: use the stripslashes(string s) function to remove all those
pesky little double slashes out of your strings. But be warned, you
might run into problem if you try to insert into a database or print to
a file or port.