Search code examples
phppreg-replacepreg-match

PHP preg_replace Strips Quotes


I want to strip out any character that is above ASCII 127. I have the following regular expression which works well except it strips out quotes ("). How can I get the results I need?

$text = preg_replace('/[^A-Za-z0-9\.\\"\/+() -]/', '', $text);

Solution

  • change your regular expression from your regular expression like below:-

    <?php
        $text = 'daasdsadsdasAAASDSDWEEQE~!@#$$%^%%&^*&()(_()_"';
    $text = preg_replace('/[^A-Za-z0-9\.\"\/+() -]/', '', $text);
    echo $text;
    ?>
    

    Output:- https://eval.in/394254