如何用单引号替换双引号

发布于 2024-08-24 07:50:44 字数 77 浏览 4 评论 0原文

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

夏有森光若流苏 2024-08-31 07:50:44
str_replace('"', "'", $text);

或重新分配它

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

or Re-assign it

$text = str_replace('"', "'", $text);
笑梦风尘 2024-08-31 07:50:44

使用

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

Use

$str = str_replace('"','\'',$str)
橘寄 2024-08-31 07:50:44

尝试使用 preg_replace,

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

Try with preg_replace,

<?php
$string="hello \" sdfsd \" dgf";
echo $string,"\n";
echo preg_replace("/\"/","'",$string);
?>
风尘浪孓 2024-08-31 07:50:44

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

<?php

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

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");
?>
你是暖光i 2024-08-31 07:50:44

尝试使用 strtr,

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

Try with strtr,

<?php
$string="hello \" sdfsd dgf";
echo $string;
$string = strtr($string, "\"", "'");
echo $string;
?>
不美如何 2024-08-31 07:50:44

对于 PHP 5.3.7

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

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

PHP 5.2

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

For PHP 5.3.7

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

OR

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

For PHP 5.2

$str = str_replace('"',"'",$str);
爱人如己 2024-08-31 07:50:44

试试这个

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

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

Try this

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

//double qoutes
$content = str_replace('\"', '"', $content); 
卷耳 2024-08-31 07:50:44

我喜欢使用中间变量:

$OutText = str_replace('"',"'",$InText);

另外,您应该有一个 Test.php 文件,您可以在其中尝试一些东西:

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

z

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文