Jump to content

Recommended Posts

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?  ???

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

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?

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; &#38 - 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);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.