1. // 字符串替换函数,主要用于替换掉串中不安全字符使其可用于Sql语句中 
  2. function my_str_replace( $str$html_filter=true ) 
  3.     $str = trim( $str ); 
  4.     $str = addslashes$str ); 
  5.     if ( $html_filter ) $str = htmlspecialchars( $str ); 
  6.     $str = preg_replace( '/[\x00-\x08\x0b\x0c\x0e-\x1f]/'''$str ); 
  7.     return $str
  8.  
  9. //以utr-8分割中文字符串 
  10. function explode_utf8($str$len
  11.     $i = 0; 
  12.     while ($i*$len<mb_strlen($str"UTF-8")) { 
  13.         $start = $len*$i
  14.         $x[] = mb_substr($str,$start,$len,"UTF-8"); 
  15.         $i++ ; 
  16.     } 
  17.     return $x
  18.  
  19. //判断是否utf-8  
  20. function is_utf8($word
  21.      if (preg_match("/^([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}$/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){2,}/",$word) == true) 
  22.     { 
  23.         return true; 
  24.     } 
  25.     else 
  26.     { 
  27.         return false; 
  28.     }