filter');
$arr = array_value($filter, $type);
$enable = array_value($arr, 'enable');
$wordarr = array_value($arr, 'keyword');
if (0 == $enable || empty($wordarr)) return FALSE;
foreach ($wordarr as $_keyword) {
$r = strpos(strtolower($keyword), strtolower($_keyword));
if (FALSE !== $r) {
$error = $_keyword;
return TRUE;
}
}
return FALSE;
}
// return http://domain.com OR https://domain.com
function url_prefix()
{
$http = ((isset($_SERVER['HTTPS']) && 'on' == $_SERVER['HTTPS']) || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
return $http . $_SERVER['HTTP_HOST'];
}
// 鍞竴韬唤ID
function uniq_id()
{
return uniqid(substr(md5(microtime(true) . mt_rand(1000, 9999)), 8, 8));
}
// 鐢熸垚璁㈠崟鍙 14浣
function trade_no()
{
$trade_no = str_replace('.', '', microtime(1));
$strlen = mb_strlen($trade_no, 'UTF-8');
$strlen = 14 - $strlen;
$str = '';
if ($strlen) {
for ($i = 0; $i <= $strlen; $i++) {
if ($i < $strlen) $str .= '0';
}
}
return $trade_no . $str;
}
// 鐢熸垚璁㈠崟鍙 16浣
function trade_no_16()
{
$explode = explode(' ', microtime());
$trade_no = $explode[1] . mb_substr($explode[0], 2, 6, 'UTF-8');
return $trade_no;
}
// 褰撳墠骞寸殑澶╂暟
function date_year($time = NULL)
{
$time = intval($time) ? $time : time();
return date('L', $time) + 365;
}
// 褰撳墠骞翠唤涓殑绗嚑澶
function date_z($time = NULL)
{
$time = intval($time) ? $time : time();
return date('z', $time);
}
// 褰撳墠鏈堜唤涓殑绗嚑澶╋紝娌℃湁鍓嶅闆 1 鍒 31
function date_j($time = NULL)
{
$time = intval($time) ? $time : time();
return date('j', $time);
}
// 褰撳墠鏈堜唤涓殑绗嚑澶╋紝鏈夊墠瀵奸浂鐨2浣嶆暟瀛 01 鍒 31
function date_d($time = NULL)
{
$time = intval($time) ? $time : time();
return date('d', $time);
}
// 褰撳墠鏃堕棿涓烘槦鏈熶腑鐨勭鍑犲ぉ 鏁板瓧琛ㄧず 1琛ㄧず鏄熸湡涓 鍒 7琛ㄧず鏄熸湡澶
function date_w_n($time = NULL)
{
$time = intval($time) ? $time : time();
return date('N', $time);
}
// 褰撳墠鏃ョ鍑犲懆
function date_d_w($time = NULL)
{
$time = intval($time) ? $time : time();
return date('W', $time);
}
// 褰撳墠鍑犳湀 娌℃湁鍓嶅闆1-12
function date_n($time = NULL)
{
$time = intval($time) ? $time : time();
return date('n', $time);
}
// 褰撳墠鏈堢殑澶╂暟
function date_t($time = NULL)
{
$time = intval($time) ? $time : time();
return date('t', $time);
}
// 0 o'clock on the day
function clock_zero()
{
return strtotime(date('Ymd'));
}
// 24 o'clock on the day
function clock_twenty_four()
{
return strtotime(date('Ymd')) + 86400;
}
// 8鐐硅繃鏈 / expired at 8 a.m.
function eight_expired($time = NULL)
{
$time = intval($time) ? $time : time();
// 褰撳墠鏃堕棿澶т簬8鐐瑰垯鏀逛负绗簩澶8鐐硅繃鏈
$life = date('G') <= 8 ? (strtotime(date('Ymd')) + 28800 - $time) : clock_twenty_four() - $time + 28800;
return $life;
}
// 24鐐硅繃鏈 / expired at 24 a.m.
function twenty_four_expired($time = NULL)
{
$time = intval($time) ? $time : time();
$twenty_four = clock_twenty_four();
$life = $twenty_four - $time;
return $life;
}
/**
* @param $url 鎻愪氦鍦板潃
* @param string $post POST鏁扮粍 / 绌轰负GET鑾峰彇鏁版嵁 / $post='GET'鑾峰彇杩炵画璺宠浆鏈缁圲RL
* @param string $cookie cookie
* @param int $timeout 瓒呮椂
* @param int $ms 璁句负1鏄绉
* @return mixed 杩斿洖鏁版嵁
*/
function https_request($url, $post = '', $cookie = '', $timeout = 30, $ms = 0)
{
if (empty($url)) return FALSE;
if (version_compare(PHP_VERSION, '5.2.3', '<')) {
$ms = 0;
$timeout = 30;
}
is_array($post) and $post = http_build_query($post);
// 娌℃湁瀹夎curl 浣跨敤http鐨勫舰寮忥紝鏀寔post
if (!extension_loaded('curl')) {
//throw new Exception('server not install CURL');
if ($post) {
return https_post($url, $post, $cookie, $timeout);
} else {
return http_get($url, $cookie, $timeout);
}
}
is_array($cookie) and $cookie = http_build_query($cookie);
$curl = curl_init();
// 杩斿洖鎵ц缁撴灉锛屼笉杈撳嚭
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
//php5.5璺焢hp5.6涓殑CURLOPT_SAFE_UPLOAD鐨勯粯璁ゅ间笉鍚
if (class_exists('\CURLFile')) {
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
} else {
defined('CURLOPT_SAFE_UPLOAD') and curl_setopt($curl, CURLOPT_SAFE_UPLOAD, false);
}
// 璁惧畾璇锋眰鐨凴UL
curl_setopt($curl, CURLOPT_URL, $url);
// 璁惧畾杩斿洖淇℃伅涓寘鍚搷搴斾俊鎭ご
if (ini_get('safe_mode') && ini_get('open_basedir')) {
// $post鍙傛暟蹇呴』涓篏ET
if ('GET' == $post) {
// 瀹夊叏妯″紡鏃跺皢澶存枃浠剁殑淇℃伅浣滀负鏁版嵁娴佽緭鍑
curl_setopt($curl, CURLOPT_HEADER, true);
// 瀹夊叏妯″紡閲囩敤杩炵画鎶撳彇
curl_setopt($curl, CURLOPT_NOBODY, true);
}
} else {
curl_setopt($curl, CURLOPT_HEADER, false);
// 鍏佽璺宠浆10娆
curl_setopt($curl, CURLOPT_MAXREDIRS, 10);
// 浣跨敤鑷姩璺宠浆锛岃繑鍥炴渶鍚庣殑Location
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
}
$ua1 = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1';
$ua = empty($_SERVER["HTTP_USER_AGENT"]) ? $ua1 : $_SERVER["HTTP_USER_AGENT"];
curl_setopt($curl, CURLOPT_USERAGENT, $ua);
// 鍏煎HTTPS
if (FALSE !== stripos($url, 'https://')) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
//ssl鐗堟湰鎺у埗
//curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
curl_setopt($curl, CURLOPT_SSLVERSION, true);
}
$header = array('Content-type: application/x-www-form-urlencoded;charset=UTF-8', 'X-Requested-With: XMLHttpRequest');
$cookie and $header[] = "Cookie: $cookie";
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
if ($post) {
// POST
curl_setopt($curl, CURLOPT_POST, true);
// 鑷姩璁剧疆Referer
curl_setopt($curl, CURLOPT_AUTOREFERER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
}
if ($ms) {
curl_setopt($curl, CURLOPT_NOSIGNAL, true); // 璁剧疆姣瓒呮椂
curl_setopt($curl, CURLOPT_TIMEOUT_MS, intval($timeout)); // 瓒呮椂姣
} else {
curl_setopt($curl, CURLOPT_TIMEOUT, intval($timeout)); // 绉掕秴鏃
}
//浼樺厛瑙f瀽 IPv6 瓒呮椂鍚嶪Pv4
//curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
// 杩斿洖鎵ц缁撴灉
$output = curl_exec($curl);
// 鏈夋晥URL锛岃緭鍑篣RL闈濽RL椤甸潰鍐呭 CURLOPT_RETURNTRANSFER 蹇呴』涓篺alse
'GET' == $post and $output = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
curl_close($curl);
return $output;
}
function save_image($img)
{
$ch = curl_init();
// 璁惧畾璇锋眰鐨凴UL
curl_setopt($ch, CURLOPT_URL, $img);
// 璁惧畾杩斿洖淇℃伅涓寘鍚搷搴斾俊鎭ご 鍚敤鏃朵細灏嗗ご鏂囦欢鐨勪俊鎭綔涓烘暟鎹祦杈撳嚭
//curl_setopt($ch, CURLOPT_HEADER, false);
//curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
// true琛ㄧず$html,false琛ㄧずecho $html
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
// 璁$畻瀛椾覆瀹藉害:鍓т腑瀵归綈(瀛椾綋澶у皬/瀛椾覆鍐呭/瀛椾綋閾炬帴/鑳屾櫙瀹藉害/鍊嶆暟)
function calculate_str_width($size, $str, $font, $width, $multiple = 2)
{
$box = imagettfbbox($size, 0, $font, $str);
return ($width - $box[4] - $box[6]) / $multiple;
}
// 鎼滅储鐩綍涓嬬殑鏂囦欢 姣斿鏂囦欢鍚庣紑
function search_directory($path)
{
if (is_dir($path)) {
$paths = scandir($path);
foreach ($paths as $val) {
$sub_path = $path . '/' . $val;
if ('.' == $val || '..' == $val) {
continue;
} else if (is_dir($sub_path)) {
//echo '鐩綍鍚:' . $val . '
';
search_directory($sub_path);
} else {
//echo ' 鏈搴曞眰鏂囦欢: ' . $path . '/' . $val . '