James
James

Reputation: 43647

How do I remove quotes from a string?

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

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

Upvotes: 66

Views: 213980

Answers (2)

Julio Popócatl
Julio Popócatl

Reputation: 782

You can do the same in one line:

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

Upvotes: 15

J V
J V

Reputation: 11936

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

Upvotes: 143

Related Questions