class f{ #文件名$f,数组$a,文本$s function zu($arr) { foreach ($arr as $v) { yield $v; } } function curl($url) { //初始化 $ch = curl_init(); //设置选项,包括URL curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); $output = curl_exec($ch); //执行并获取HTML文档内容 //$str = htmlspecialchars($output);//转换为源代码形式 //释放curl句柄 curl_close($ch); return $output; } function dk($l) //打开一个链接或文件,返回字符串 { if ($this->bh($l, 'http')) { return $this->curl($l); } else { return @file_get_contents($l); } } function bl($dir = '*_') { //遍历 $dirInfo = array(); foreach ($this->zu(glob($dir, GLOB_NOSORT)) as $v) { if (!is_dir($v)) { $dirInfo[] = $v; } if (is_dir($v)) { $dirInfo[] = $v; $dirInfo = array_merge($dirInfo, $this->bl($v . '/*')); } } return $dirInfo; } function sc($p) { if (is_dir($p)) { foreach ($this->zu($this->bl($p)) as $v) { (is_dir($v)) ? rmdir($v) : unlink($v); } return rmdir($p); } } function kzm($f) { return pathinfo($f, PATHINFO_EXTENSION); } function wjm($f) { return pathinfo($f, PATHINFO_BASENAME); } function lj($f) { return pathinfo($f, PATHINFO_DIRNAME); } function cz($f) { return file_exists($f); } function th($s,$a){ return strtr($s, $a); } function hc($a,$zf=""){ return implode($zf, $a); } function bh($s_fu, $s_zi) //字符串包含 { return stristr($s_fu, $s_zi); } function zz($zz, $s) { preg_match_all($zz, $s, $match); return $match; } function fg($s, $zf=',') { return (explode($zf, $s)); } function tc() { if(session_destroy()){ echo "<script> alert('退出成功!');location.href='/'; </script> "; } } function tj($l, $s, $zhuijia = "0") //添加内容 { if (!$this->cz(dirname($l))) { mkdir(dirname($l), 0777, true); } if ($zhuijia == "0") { return file_put_contents($l, $s); } if ($zhuijia == "1") { return file_put_contents($l, $s, FILE_APPEND); } if ($zhuijia == "2") { return file_put_contents($l, $s, LOCK_EX); } } function kg($str) { $qian = array(" ", " ", "\t", "\n", "\r"); return str_replace($qian, '', $str); } function ys($str) { return gzdeflate($str); } function jys($str) { return gzinflate($str); } /** * 截取字符串 * $str => 要截取的原字符串 * $length => 要截取的长度 * $type => 是否在最后加“...” 1为不加,否则为加 * **/ function jq($str, $length, $type = 1) { $len = strlen($str); $r = array(); $n = 0; $m = 0; for ($i = 0; $i < $len; $i++) { $x = substr($str, $i, 1 ); $a = base_convert(ord($x), 10, 2); $a = substr('00000000' . $a, -8); if (substr($a, 0, 1) == 0) { $r[] = substr($str, $i, 1 ); } elseif (substr($a, 0, 3) == 110 ) { $r[] = substr($str, $i, 2 ); $i += 1; } elseif (substr($a, 0, 4) == 1110 ) { $r[] = substr($str, $i, 3 ); $i += 2; } else { $r[] = ''; } if (++$m >= $length) { break; } } return join($r) . ($type != 1 ? "..." : ""); } }