发信人: xuefer()
整理人: dalasthunder(2003-03-13 16:02:50), 站内信件
|
function gbk_escape_string($source, $quotechar = "'")
{
$result = "";
while (preg_match("/^([\x81-\xFE][\x40-\x7E\x80-\xFE]|.)(.*)$/",
$source, $matches)) {
if (strlen($matches[1]) == 1) {
$escapedchar = mysql_escape_string($matches[1]);
if (strlen($escapedchar) > 1) {
$result .= $quotechar . " " . $quotechar;
}
$result .= $escapedchar;
} else {
$result .= $matches[1];
}
$source = $matches[2];
}
return $result;
}
由于某种原因(bug)导致 gbk mysql 无法处理blob数据
以上脚本来代替 mysql_escale_string() or addslashes(用于SQL), 仅用于 mysql 是gbk字符集!
次脚本请教于 Wei He (mysql的贡献者之一)
建议加精华了 |
|