如何从字符串中删除引号?

发布于 2024-10-03 01:47:57 字数 138 浏览 1 评论 0原文

$string = "my text has \"double quotes\" and 'single quotes'";

如何从 $string 中删除所有类型的引号(不同语言)?

$string = "my text has \"double quotes\" and 'single quotes'";

How to remove all types of quotes (different languages) from $string?

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

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

发布评论

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

评论(2

错爱 2024-10-10 01:47:57
str_replace('"', "", $string);
str_replace("'", "", $string);

我猜你的意思是引号?

否则,使用一些正则表达式,这将适用于 html 引号,例如:

preg_replace("/<!--.*?-->/", "", $string);

C 样式引号:

preg_replace("/\/\/.*?\n/", "\n", $string);

CSS 样式引号:

preg_replace("/\/*.*?\*\//", "", $string);

bash 样式引号:

preg-replace("/#.*?\n/", "\n", $string);

等等...

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

I assume you mean quotation marks?

Otherwise, go for some regex, this will work for html quotes for example:

preg_replace("/<!--.*?-->/", "", $string);

C-style quotes:

preg_replace("/\/\/.*?\n/", "\n", $string);

CSS-style quotes:

preg_replace("/\/*.*?\*\//", "", $string);

bash-style quotes:

preg-replace("/#.*?\n/", "\n", $string);

Etc etc...

只是我以为 2024-10-10 01:47:57

您可以在一行中执行相同的操作:

str_replace(['"',"'"], "", $text)

You can do the same in one line:

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