Mike Rifgin
Mike Rifgin

Reputation: 10745

replace double quotes with single quotes in a string

I know this sounds simple, and probably is, but I can't seem ot get this working. Just want to replace all occurences of a double quote with a single quote...tired this but it doesn't work:

$con = str_replace("\"", "'", $content);

Upvotes: 0

Views: 3951

Answers (3)

Chris Swanson
Chris Swanson

Reputation: 11

I had the same problem with input from a form.

I used &ampquot; for my search string and it worked great.

$con = str_replace("&ampquot;", "'", $content);

Upvotes: 1

Tomasz Struczyński
Tomasz Struczyński

Reputation: 3303

What you do is correct and should work. If it doesn't, then you may only SEE double quotes, but in reality these are other characters. Possible is html " character rendered as ". There are also several chars very similar to double quotes. hey 'happen' especially when pasting text from word or openoffice. You'll include all possibilities in str_replace (it can take arrays of strings as parameters).

Upvotes: 1

Andrei Serdeliuc ॐ
Andrei Serdeliuc ॐ

Reputation: 5878

Or:

$con = str_replace(chr(34), chr(39), $content);

Upvotes: 1

Related Questions