php sqlite insert into 插入内容带双引号,单引号

180it 2020-02-15 PM 3484℃ 0条

$text1=escape_string(text1);
$text2=escape_string(text2);

insert into MINGYAN (Content1,Content2,Content3,View) VALUES ('$text1','$text2','$time',0);

function escape_string($string, $quotestyle='both') {

    if( function_exists('sqlite_escape_string') ){
        $string = sqlite_escape_string($string);
        $string = str_replace("''","'",$string); #- no quote escaped so will work like with no sqlite_escape_string available
    }
    else{
        $escapes = array("\x00", "\x0a", "\x0d", "\x1a", "\x09","\\");
        $replace = array('\0',   '\n',    '\r',   '\Z' , '\t',  "\\\\");
    }
    switch(strtolower($quotestyle)){
        case 'double':
        case 'd':
        case '"':
            $escapes[] = '"';
            $replace[] = '\"';
            break;
        case 'single':
        case 's':
        case "'":
            $escapes[] = "'";
            $replace[] = "''";
            break;
        case 'both':
        case 'b':
        case '"\'':
        case '\'"':
            $escapes[] = '"';
            $replace[] = '\"';
            $escapes[] = "'";
            $replace[] = "''";
            break;
    }
    return str_replace($escapes,$replace,$string);
} 

支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

php sqlite insert into 插入内容带双引号,单引号