我该如何使用PHP将""
(双引号)替换为''
(单引号)?
str_replace('"', "'", $text);
或者重新分配它
$text = str_replace('"', "'", $text);
$text = str_replace('"',"'",$text);
我必须提到这一点,因为我刚刚犯了这个错误。 - SSH This使用
$str = str_replace('"','\'',$str)
试试使用 preg_replace 函数。
<?php
$string="hello \" sdfsd \" dgf";
echo $string,"\n";
echo preg_replace("/\"/","'",$string);
?>
您可以使用str_replace函数,尝试使用http://php.net/manual/en/function.str-replace.php它包含了许多PHP文档。
<?php
echo str_replace("\"","'","\"\"\"\"\" hello world\n");
?>
<?php
$string="hello \" sdfsd dgf";
echo $string;
$string = strtr($string, "\"", "'");
echo $string;
?>
对于PHP 5.3.7版本
$str = str_replace('"',''',$str);
或者
$str = str_replace('"',"'",$str);
针对PHP 5.2
$str = str_replace('"',"'",$str);
试试这个
//single qoutes
$content = str_replace("\'", "'", $content);
//double qoutes
$content = str_replace('\"', '"', $content);
我喜欢使用中间变量:
$OutText = str_replace('"',"'",$InText);
另外,你应该有一个Test.php文件,在那里你可以尝试一些东西:
$QText = 'I "am" quoted';
echo "<P>QText is: $QText";
$UnQText = str_replace ('"', '', $QText);
echo "<P>Unquoted is: $UnQText";
z
"Testing"
,您想要的是'Testing'
,反之亦然?那么如果有一个字符串"They're"
,您想要的是'They"re'
吗? - gnarf