如何使用PHP替换""
(我认为它被称为双引号)与''
(我认为它称为单引号)?
str_replace('"', "'", $text);
或重新分配
$text = str_replace('"', "'", $text);
使用
$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");
?>
试试strtr,
<?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);
我喜欢使用中间变量:
$OutText = str_replace('"',"'",$InText);
此外,您应该有一个Test.php文件,您可以尝试填写:
$QText = 'I "am" quoted';
echo "<P>QText is: $QText";
$UnQText = str_replace ('"', '', $QText);
echo "<P>Unquoted is: $UnQText";
从
试试这个
//single qoutes
$content = str_replace("\'", "'", $content);
//double qoutes
$content = str_replace('\"', '"', $content);