如何用单引号替换双引号

时间:2022-09-15 16:01:06

How can I replace "" (I think it's called double quotes) with '' (I think its called single quotes) using PHP?

如何使用PHP替换“”(我认为它被称为双引号)与''(我认为它称为单引号)?

8 个解决方案

#1


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

or Re-assign it

或重新分配

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

#2


Use

$str = str_replace('"','\'',$str)

#3


Try with preg_replace,

试试preg_replace,

<?php$string="hello \" sdfsd \" dgf";echo $string,"\n";echo preg_replace("/\"/","'",$string);?>

#4


You can use str_replace, try to use http://php.net/manual/en/function.str-replace.php it contains allot of php documentation.

你可以使用str_replace,尝试使用http://php.net/manual/en/function.str-replace.php它包含分配的php文档。

<?phpecho str_replace("\"","'","\"\"\"\"\" hello world\n");?>

#5


Try with strtr,

试试strtr,

<?php$string="hello \" sdfsd dgf";echo $string;$string = strtr($string, "\"", "'");echo $string;?>

#6


For PHP 5.3.7

对于PHP 5.3.7

$str = str_replace('&quot;','&#39;',$str);

OR

$str = str_replace('&quot;',"'",$str);

For PHP 5.2

对于PHP 5.2

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

#7


I like to use an intermediate variable:

我喜欢使用中间变量:

$OutText = str_replace('"',"'",$InText);

Also, you should have a Test.php file where you can try stuff out:

此外,您应该有一个Test.php文件,您可以尝试填写:

$QText = 'I "am" quoted';echo "<P>QText is: $QText";$UnQText = str_replace ('"', '', $QText);echo "<P>Unquoted is: $UnQText";

z

#8


Try this

//single qoutes$content = str_replace("\'", "'", $content); //double qoutes$content = str_replace('\"', '"', $content); 

#1


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

or Re-assign it

或重新分配

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

#2


Use

$str = str_replace('"','\'',$str)

#3


Try with preg_replace,

试试preg_replace,

<?php$string="hello \" sdfsd \" dgf";echo $string,"\n";echo preg_replace("/\"/","'",$string);?>

#4


You can use str_replace, try to use http://php.net/manual/en/function.str-replace.php it contains allot of php documentation.

你可以使用str_replace,尝试使用http://php.net/manual/en/function.str-replace.php它包含分配的php文档。

<?phpecho str_replace("\"","'","\"\"\"\"\" hello world\n");?>

#5


Try with strtr,

试试strtr,

<?php$string="hello \" sdfsd dgf";echo $string;$string = strtr($string, "\"", "'");echo $string;?>

#6


For PHP 5.3.7

对于PHP 5.3.7

$str = str_replace('&quot;','&#39;',$str);

OR

$str = str_replace('&quot;',"'",$str);

For PHP 5.2

对于PHP 5.2

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

#7


I like to use an intermediate variable:

我喜欢使用中间变量:

$OutText = str_replace('"',"'",$InText);

Also, you should have a Test.php file where you can try stuff out:

此外,您应该有一个Test.php文件,您可以尝试填写:

$QText = 'I "am" quoted';echo "<P>QText is: $QText";$UnQText = str_replace ('"', '', $QText);echo "<P>Unquoted is: $UnQText";

z

#8


Try this

//single qoutes$content = str_replace("\'", "'", $content); //double qoutes$content = str_replace('\"', '"', $content);