reverse mysql_real_escape_string

后端 未结 3 843
北恋
北恋 2021-02-19 08:28

I have a piece of data that is large and will probably contain quotes and double quotes.

I\'m using mysql_real_escape_string() to store it safely.

W

相关标签:
3条回答
  • 2021-02-19 08:31

    If you actually want to reverse that because of how your data is formatted, this is a solution I came up with:

    function mysql_unreal_escape_string($string) {
        $characters = array('x00', 'n', 'r', '\\', '\'', '"','x1a');
        $o_chars = array("\x00", "\n", "\r", "\\", "'", "\"", "\x1a");
        for ($i = 0; $i < strlen($string); $i++) {
            if (substr($string, $i, 1) == '\\') {
                foreach ($characters as $index => $char) {
                    if ($i <= strlen($string) - strlen($char) && substr($string, $i + 1, strlen($char)) == $char) {
                        $string = substr_replace($string, $o_chars[$index], $i, strlen($char) + 1);
                        break;
                    }
                }
            }
        }
        return $string;
    }
    
    0 讨论(0)
  • 2021-02-19 08:47

    Who says?

    $keyword = "TEST'TEST";
    
    $result1 = mysql_real_escape_string($keyword);
    echo $result1 --> TEST\'TEST
    
    $result2 = nl2br(stripslashes($result));
    echo $result2 --> TEST'TEST
    
    0 讨论(0)
  • 2021-02-19 08:50

    Do you use magic quotes?

    Note: If magic_quotes_gpc is enabled, first apply stripslashes() to the data. Using this function [mysql_real_escape_string] on data which has already been escaped will escape the data twice.

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