php 如何用单引号替换双引号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2424281/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:24:26  来源:igfitidea点击:

How do I replace double quotes with single quotes

phpregexquotes

提问by streetparade

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

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

回答by YOU

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

or Re-assign it

或重新分配

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

回答by codaddict

Use

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

回答by sganesh

Try with preg_replace,

尝试使用 preg_replace,

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

回答by Nick Hermans

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

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

<?php

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

回答by karthi_ms

Try with strtr,

尝试使用 strtr,

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

回答by Pritam Prasun

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);

回答by Shaik Matheen

Try this

尝试这个

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

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

回答by Zardiw

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

z