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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4228282/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 12:20:32  来源:igfitidea点击:

How do I remove quotes from a string?

phpquotes

提问by James

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

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

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

回答by J V

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:

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

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

C-style quotes:

C风格的报价:

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

CSS-style quotes:

CSS 风格的引号:

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

bash-style quotes:

bash 风格的报价:

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

Etc etc...

等等等等...