How do I remove quotes from a string?

PhpQuotes

Php Problem Overview


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

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

Php Solutions


Solution 1 - Php

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

Solution 2 - Php

You can do the same in one line:

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

Solution 3 - Php

You can do the following:

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJamesView Question on Stackoverflow
Solution 1 - PhpJ VView Answer on Stackoverflow
Solution 2 - PhpJulio PopócatlView Answer on Stackoverflow
Solution 3 - PhpOussamaView Answer on Stackoverflow