- // 字符串替换函数,主要用于替换掉串中不安全字符使其可用于Sql语句中
- function my_str_replace( $str, $html_filter=true )
- {
- $str = trim( $str );
- $str = addslashes( $str );
- if ( $html_filter ) $str = htmlspecialchars( $str );
- $str = preg_replace( '/[\x00-\x08\x0b\x0c\x0e-\x1f]/', '', $str );
- return $str;
- }
- //以utr-8分割中文字符串
- function explode_utf8($str, $len)
- {
- $i = 0;
- while ($i*$len<mb_strlen($str, "UTF-8")) {
- $start = $len*$i;
- $x[] = mb_substr($str,$start,$len,"UTF-8");
- $i++ ;
- }
- return $x;
- }
- //判断是否utf-8
- function is_utf8($word)
- {
- 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)
- {
- return true;
- }
- else
- {
- return false;
- }
- }