Php 如何用单引号替换双引号
如何使用PHP将Php 如何用单引号替换双引号,php,regex,quotes,Php,Regex,Quotes,如何使用PHP将”(我认为它被称为双引号)替换为”(我认为它被称为单引号) str_replace('"', "'", $text); 或者重新分配它 $text = str_replace('"', "'", $text); 使用 您可以使用str_replace,尝试使用它包含的php文档 <?php echo str_replace("\"","'","\"\"\"\"\" hello world\n"); ?> 尝试使用strtr <?php $string="
”
(我认为它被称为双引号)替换为”
(我认为它被称为单引号)
str_replace('"', "'", $text);
或者重新分配它
$text = str_replace('"', "'", $text);
使用
您可以使用str_replace,尝试使用它包含的php文档
<?php
echo str_replace("\"","'","\"\"\"\"\" hello world\n");
?>
尝试使用strtr
<?php
$string="hello \" sdfsd dgf";
echo $string;
$string = strtr($string, "\"", "'");
echo $string;
?>
尝试使用preg\u replace
<?php
$string="hello \" sdfsd \" dgf";
echo $string,"\n";
echo preg_replace("/\"/","'",$string);
?>
PHP 5.3.7的
$str = str_replace('"',''',$str);
或
对于PHP5.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";
$QText='I'am'quoted';
echo“QText是:$QText”;
$UnQText=str_replace(“,”$QText);
echo“
Unquoted is:$UnQText”;
z试试这个
//single qoutes
$content = str_replace("\'", "'", $content);
//double qoutes
$content = str_replace('\"', '"', $content);
假设你有“测试”
-你想要“测试”
-反之亦然?那么“他们”
-你想要“他们”
?是的,这是对的,但只是我的一个新评论。这本身并不会改变$text的值,您需要将整个值设置为$text,如下所示:$text=str_replace(“,“,”,$text);
必须提到这一点,因为我刚刚做了这个mistake@SSHThis我做过一次。我花了一个小时才弄清楚出了什么问题。这是个新犯的错误!
$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);