Home » Php » php – How do I remove quotes from a string?

php – How do I remove quotes from a string?

Posted by: admin April 23, 2020 Leave a comment

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

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

How to&Answers:
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…