-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathfunc.php
More file actions
55 lines (50 loc) · 1.63 KB
/
Copy pathfunc.php
File metadata and controls
55 lines (50 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
require_once("config.php");
check_ip($IP_WHITE_LIST);
function check_ip($ip_list){
$ip = $_SERVER['REMOTE_ADDR'];
if (! in_array($ip, $ip_list)) {
header('HTTP/1.0 403 Forbidden');
die('Your IP address (' . $ip . ') is not authorized to access this file.');
}
}
function is_empty($C_char){
if (empty($C_char)) return true; //判断是否已定义字符串
if ($C_char=='') return true; //判断字符串是否为空
return false;
}
function utf8_length($str){
$count = 0;
if (!empty($str) && $str != ''){
preg_match_all('/[\x{4e00}-\x{9fa5}]/u', $str, $chinese);
preg_match_all('/[^\x{4e00}-\x{9fa5}]/u', $str, $string);
$str_array = array_merge(current($chinese), current($string));
for($i=0;$i<count($str_array);$i++){
if (strlen($str_array[$i]) == 1) $count = $count + 0.5;
else $count = $count + 1;
}
}
return $count;
}
function utf8_substring($str,$length){
$result = '';
$count = 0;
if (!empty($str) && $str != ''){
preg_match_all('/[\x{4e00}-\x{9fa5}]/u', $str, $chinese);
preg_match_all('/[^\x{4e00}-\x{9fa5}]/u', $str, $string);
$str_array = array_merge(current($chinese), current($string));
for($i=0;$i<count($str_array) && $count < $length;$i++){
if (strlen($str_array[$i]) == 1){
$count = $count + 0.5;
}
else {
$count = $count + 1;
}
$result = $result . $str_array[$i];
}
}
return $result;
}
function is_url($url) {
return !is_empty(parse_url($url,PHP_URL_SCHEME));
}