kqlambert
kqlambert

Reputation: 2711

php string replace quotes

Hello I am trying to get all single quotes to be double quotes using the php str_replace however it does not seem to be working no matter what I do, suggestions

$page = str_replace("/'/", '/"/', $page);

Upvotes: 3

Views: 37083

Answers (7)

BluesRockAddict
BluesRockAddict

Reputation: 15683

Update: I'd agree with others that the following is an easier-to-read alternative for most folks:

$page = str_replace("'", '"', $page);

My original answer:

$page = str_replace(chr(39), chr(34), $page);

Upvotes: 21

user557846
user557846

Reputation:

This should work:

str_replace("'",'"',$text);

Upvotes: 2

0b10011
0b10011

Reputation: 18795

You only need the start and end / for preg_...() (and other regex) functions. For basic functions such as str_replace, simply use the characters:

str_replace("'", '"', $text);

Upvotes: 0

alex
alex

Reputation: 490607

You don't need to escape the quote character (in fact it is \, not /, unless you were confused with the standard regex delimiters) if the string isn't delimited with the same character.

$page = str_replace("'", '"', $page);

Upvotes: 4

Robert Wilson
Robert Wilson

Reputation: 669

This works. You actually don't need any escaping character.

$page = str_replace("'", '"', $page);

Upvotes: 0

Sampo Sarrala
Sampo Sarrala

Reputation: 4888

I think you should do replacements with preg_replace();

$str = "'Here 'it' goes'";
echo preg_replace("/'/", '"', $str);

Upvotes: 0

Patrick Lorio
Patrick Lorio

Reputation: 5668

$page = str_replace("'", "\"", $page);

Upvotes: 0

Related Questions