How do I replace double quotes with single quotes

佐手、 提交于 2019-11-27 04:35:46
str_replace('"', "'", $text);

or Re-assign it

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

Use

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

Try with preg_replace,

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

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

<?php

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

Try with strtr,

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

For PHP 5.3.7

$str = str_replace('&quot;','&#39;',$str);

OR

$str = str_replace('&quot;',"'",$str);

For PHP 5.2

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

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:

$QText = 'I "am" quoted';
echo "<P>QText is: $QText";
$UnQText = str_replace ('"', '', $QText);
echo "<P>Unquoted is: $UnQText";

z

Try this

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

//double qoutes
$content = str_replace('\"', '"', $content); 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!