|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello. I am trying to allow users to enter apostrophes into html form fields, but I am encountering a lot of problems. It seems that automatically the $_POST variable inserts a \' for every apostrophe. This would be find except that now I have a php variable with a \' in it. Here is the problem:
$form_input = "John's Party" If I use echo "$form_input"; => John\'s Party If I use echo '$form_input'; => $form_input If I use strtr("\","","$form_input) or str_replace("/","",$form_input) => I get a parse error because it recognizes \" as one character. How can I get rid of the \. I use "" for all my echo statements so I don't ever need it anyway. THANK YOU FOR YOUR HELP. THIS IS REALLY STUMPING ME (Yes, I'm pretty new to PHP). |
|
#2
|
|||
|
|||
|
Theres a php function called strip_slashes (might be stripSlashes) that will remove them for you.
-KM- |
|
#3
|
|||
|
|||
|
When you enclose a variable name in apostrophes, PHP thinks you want to display the field.
HTH, Bud |
|
#4
|
||||
|
||||
|
If I use strtr("\","","$form_input) or str_replace("/","",$form_input)
You have to escape the slash... str_replace("\\","",$form_input) would have worked... A slash itself is usually used to escape special characters in a string (such as single quote, double quotes, and a backslash)... For example, if you wanted to put quotes in your string you would use \" within the string... when printed to the screen it usually displays without the backslash... Example: $str="So then he said \"Spam sucks\""; $coolW="\\/\\/"; (would display \/\/) $str="So then he said "Spam sucks""; would throw an error However, in your case stripslashes() is a much better solution =) |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Please help me allow apostrophes(') in form fields |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|