[英]How do I replace double quotes with single quotes
如何使用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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.