如何用单引号替换双引号

str*_*ade 32 php regex quotes

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

YOU*_*YOU 85

str_replace('"', "'", $text);
Run Code Online (Sandbox Code Playgroud)

或重新分配

$text = str_replace('"', "'", $text);
Run Code Online (Sandbox Code Playgroud)

  • 是的,这是对的,但只是我的新评论.这实际上不会改变$ text的值,你需要将整个东西设置为$ text,如下所示:`$ text = str_replace('"',''",$ text);`Just不得不提这个,因为我犯了这个错误 (6认同)

cod*_*ict 6

使用

$str = str_replace('"','\'',$str)
Run Code Online (Sandbox Code Playgroud)


sga*_*esh 5

尝试使用 preg_replace,

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