Search code examples
phpstringescapeutils

PHP Escape character


I'm using PHP environment and I have a problem in displaying data on form of escape characters.

example:

how could i display a double quote " if my string data is \"

same with, how could i display a backslash \ if my string data is \\


Solution

  • To remove \ characters that are used as an escape characters, use the stripslashes function.

    david@raston ~ $ cat tmp/test.php
    <?php
    
    $raw = 'double slash \\\\ escaped quote \"';
    print $raw;
    print "\n";
    print stripslashes($raw);
    ?>
    
    david@raston ~ $ php tmp/test.php
    double slash \\ escaped quote \"
    double slash \ escaped quote "