Punk Rock Geek Posted June 24, 2009 Share Posted June 24, 2009 I have a strange problem. While I know how to replace quotation marks with another character, for some reason it no longer works if the string was created using data from an input form. Here is the start of my code. The first variable was created through an html form. The second one was created without a form: $formvariable = stripslashes($formvariable); $normalvariable = '"'; If I echo $formvariable and $normalvariable at this line, they both return a double quotation mark. They are identical. My code continues: $formvariable = str_replace('"',"", $formvariable); $normalvariable = str_replace('"',"", $normalvariable); Now when I echo them both, the normalvariable's quotation mark gets replaced, while the formvariable stays the same. Even though they were both the same and they both had the same thing done to them. Anyone have any idea of what could be happening? ??? Quote Link to comment https://forums.phpfreaks.com/topic/163475-replace-quotation-marks-in-a-string-with-another-character/ Share on other sites More sharing options...
MadTechie Posted June 24, 2009 Share Posted June 24, 2009 They are either not identical or something is being changed during the (code continue) Quote Link to comment https://forums.phpfreaks.com/topic/163475-replace-quotation-marks-in-a-string-with-another-character/#findComment-862579 Share on other sites More sharing options...
patrickmvi Posted June 24, 2009 Share Posted June 24, 2009 It could be that the double quote coming from your form is actually a different double quote character with a different character code value. Try using the ord function to output each of the individual character codes to see if they match. http://www.php.net/ord Quote Link to comment https://forums.phpfreaks.com/topic/163475-replace-quotation-marks-in-a-string-with-another-character/#findComment-862589 Share on other sites More sharing options...
Punk Rock Geek Posted June 25, 2009 Author Share Posted June 25, 2009 It could be that the double quote coming from your form is actually a different double quote character with a different character code value. Try using the ord function to output each of the individual character codes to see if they match. http://www.php.net/ord Thanks. It turns out that they don't match. The formvariable is a 38 and the normalvariable is a 34. No idea of how to fix this though? Quote Link to comment https://forums.phpfreaks.com/topic/163475-replace-quotation-marks-in-a-string-with-another-character/#findComment-863229 Share on other sites More sharing options...
thebadbad Posted June 25, 2009 Share Posted June 25, 2009 If you look at an ASCII table, you can see that 34 is a double quote, and 38 actually is an ampersand (ord() only checks the first character of the input string). So I'm guessing the double quotes in $formvariable actually are HTML entities; & - representing a double quote. When you output the two variables, did you look at the source code? Always do that to be sure exactly what's output. $formvariable = str_replace('&', '', $formvariable); Quote Link to comment https://forums.phpfreaks.com/topic/163475-replace-quotation-marks-in-a-string-with-another-character/#findComment-863252 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.