[php]代码库
function array2sql($array){
$sql_array = array();
foreach ($array AS $_k=>$_v){
if (empty($_k)){
continue;
}
$_v = trim($_v);
//if (is_numeric($_v)&&preg_match("/^[1-9][0-9]+$/", $_v)){
if (ctype_digit($_v)&&preg_match("/^[1-9][0-9]+$/", $_v)){ //modified by Herman.Xi is_numeric 对十六进制数判断不了 举例:0X792496944666339
$sql_array[] = "`{$_k}`={$_v}";
} else {
$_v = Deal_SC($_v);
$sql_array[] = "`{$_k}`='{$_v}'";
}
}
return implode(',', $sql_array);
}
function Deal_SC($str){
//处理特殊字符,add by Herman.Xi @ 20130307
$str = str_replace("'","´",$str);
$str = str_replace("\"",""",$str);
$tes = array("=" , "{", "}");
foreach($tes as $v){
$str = str_replace($v,"",$str);
}
return addslashes($str);
}
[代码运行效果截图]