How do I remove quotes from a string?

夙愿已清 提交于 2019-11-27 01:27:14

问题


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

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


回答1:


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...



来源:https://stackoverflow.com/questions/4228282/how-do-i-remove-quotes-from-a-string

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