Jump to content


Photo

proper way to strip quotes?


  • Please log in to reply
3 replies to this topic

#1 Icaros

Icaros
  • Members
  • Pip
  • Newbie
  • 2 posts

Posted 08 May 2006 - 07:43 AM

i've tried using the following to remove double quotes (i'll get to single eventually) from a string that the user can enter, but it's removing the entire word in quotes.

example:

blah blah "blah"

returns:

blah blah

should be:

blah blah blah

$fixcomment = str_replace("\x22", "", $comment);

or

$fixcomment = str_replace("\"", "", $comment);

any ideas?


#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 08 May 2006 - 08:52 AM

The last thing you tried:
$fixcomment = str_replace("\"", "", $comment);
That should work...

#3 Icaros

Icaros
  • Members
  • Pip
  • Newbie
  • 2 posts

Posted 08 May 2006 - 07:26 PM

OK i got it to work, but it's a strange solution!

//Strip quotes
$fixcomment2 = str_replace('\"', '', $comment);
$comment = $fixcomment2;
$fixcomment2 = str_replace("\'", "", $comment);
$comment = $fixcomment2;

notice that for double quotes, i need to use single quotes (' \" '), but for single quotes i needed to use double (" \' "). it didn't work any other way!

#4 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 09 May 2006 - 07:46 PM

Thats strange, str_replace("\"", "", $comment) should work fine, as long as the middle quotation mark is escaped...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users