How do I remove quotes from a string?

前端 未结 1 1761
孤街浪徒
孤街浪徒 2020-12-08 18:34
$string = \"my text has \\\"double quotes\\\" and \'single quotes\'\";

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

相关标签:
1条回答
  • 2020-12-08 19:10
    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...

    0 讨论(0)
提交回复
热议问题