保存base64圖片
~~~
if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $img, $result)) {
$type = ".".$result[2];
$path = "/data/upload/api/" . date("Y-m-d") . "-" . uniqid() . $type;
}
$img = base64_decode(str_replace($result[1], '', $img));
@file_put_contents(HX_ROOT . $path, $img);
~~~
百度編輯器
需要預先加載
<script type="text/javascript" src="ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="ueditor/ueditor.all.js"></script>
~~~
function ueditor($id="content",$value="",$height="250"){
$host = SITE_URL;
$str =<<<EOF
<script id="{$id}" name="{$id}" type="text/plain">
{$value}
</script>
<script type="text/javascript">
var ue = UE.getEditor("{$id}",{
initialFrameHeight:$height,allowDivTransToP:false
});
</script>
EOF;
return $str;
}
~~~
時區數組
~~~
function get_timezone(){
return array(
'Pacific/Kwajalein'=>'(GMT -12:00) Eniwetok, Kwajalein',
'Pacific/Samoa'=>'(GMT -11:00) Midway Island, Samoa',
'US/Hawaii'=>'(GMT -10:00) Hawaii',
'US/Alaska'=>'(GMT -09:00) Alaska',
'America/Tijuana'=>'(GMT -08:00) Pacific Time (US & Canada), Tijuana',
'US/Arizona'=>'(GMT -07:00) Mountain Time (US & Canada), Arizona',
'America/Mexico_City'=>'(GMT -06:00) Central Time (US & Canada), Mexico City',
'America/Bogota'=>'(GMT -05:00) Eastern Time (US & Canada), Bogota, Lima, Quito',
'America/Caracas'=>'(GMT -04:00) Atlantic Time (Canada), Caracas, La Paz',
'Canada/Newfoundland'=>'(GMT -03:30) Newfoundland',
'America/Buenos_Aires'=>'(GMT -03:00) Brassila, Buenos Aires, Georgetown, Falkland Is',
'Atlantic/St_Helena'=>'(GMT -02:00) Mid-Atlantic, Ascension Is., St. Helena',
'Atlantic/Azores'=>'(GMT -01:00) Azores, Cape Verde Islands',
'Europe/Dublin'=>'(GMT) Casablanca, Dublin, Edinburgh, London, Lisbon, Monrovia',
'Europe/Amsterdam'=>'(GMT +01:00) Amsterdam, Berlin, Brussels, Madrid, Paris, Rome',
'Africa/Cairo'=>'(GMT +02:00) Cairo, Helsinki, Kaliningrad, South Africa',
'Asia/Baghdad'=>'(GMT +03:00) Baghdad, Riyadh, Moscow, Nairobi',
'Asia/Tehran'=>'(GMT +03:30) Tehran',
'Asia/Baku'=>'(GMT +04:00) Abu Dhabi, Baku, Muscat, Tbilisi',
'Asia/Kabul'=>'(GMT +04:30) Kabul',
'Asia/Karachi'=>'(GMT +05:00) Ekaterinburg, Islamabad, Karachi, Tashkent',
'Asia/Calcutta'=>'(GMT +05:30) Bombay, Calcutta, Madras, New Delhi',
'Asia/Katmandu'=>'(GMT +05:45) Katmandu',
'Asia/Almaty'=>'(GMT +06:00) Almaty, Colombo, Dhaka, Novosibirsk',
'Asia/Rangoon'=>'(GMT +06:30) Rangoon',
'Asia/Bangkok'=>'(GMT +07:00) Bangkok, Hanoi, Jakarta',
'Asia/Shanghai'=>'(GMT +08:00) Beijing, Hong Kong, Perth, Singapore, Taipei',
'Asia/Tokyo'=>'(GMT +09:00) Osaka, Sapporo, Seoul, Tokyo, Yakutsk',
'Australia/Adelaide'=>'(GMT +09:30) Adelaide, Darwin',
'Australia/Canberra'=>'(GMT +10:00) Canberra, Guam, Melbourne, Sydney, Vladivostok',
'Asia/Magadan'=>'(GMT +11:00) Magadan, New Caledonia, Solomon Islands',
'Pacific/Auckland'=>'(GMT +12:00) Auckland, Wellington, Fiji, Marshall Island'
);
~~~
天氣現象數組
~~~
function weather(){
return array(
"00" =>"晴",
"01"=>"多云",
"02"=>"陰",
"03"=>"陣雨",
"04"=>"雷陣雨",
"05"=>"雷陣雨伴有冰雹",
"06"=>"雨夾雪",
"07"=>"小雨",
"08"=>"中雨",
"09"=>"大雨",
"10"=>"暴雨",
"11"=>"大暴雨",
"12"=>"特大暴雨",
"13"=>"陣雪",
"14"=>"小雪",
"15"=>"中雪",
"16"=>"大雪",
"17"=>"暴雪",
"18"=>"霧",
"19"=>"凍雨",
"20"=>"沙塵暴",
"21"=>"小到中雨",
"22"=>"中到大雨",
"23"=>"大到暴雨",
"24"=>"暴雨到大暴雨",
"25"=>"大暴雨到特大暴雨",
"26"=>"小到中雪",
"27"=>"中到大雪",
"28"=>"大到暴雪",
"29"=>"浮塵",
"30"=>"揚沙",
"31"=>"強沙塵暴",
"53"=>"霾",
"99"=>"無",
"32"=>"濃霧",
"49"=>"強濃霧",
"54"=>"中度霾",
"55"=>"重度霾",
"56"=>"嚴重霾",
"57"=>"大霧",
"58"=>"特強濃霧",
"301"=>"雨",
"302"=>"雪"
);
}
~~~
/*
獲取文件MIME類型,根據文件擴展名來獲取
*/
~~~
function getFileType($ext){
static $mime_types = array (
'apk' => 'application/vnd.android.package-archive',
'3gp' => 'video/3gpp',
'ai' => 'application/postscript',
'aif' => 'audio/x-aiff',
'aifc' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'asc' => 'text/plain',
'atom' => 'application/atom+xml',
'au' => 'audio/basic',
'avi' => 'video/x-msvideo',
'bcpio' => 'application/x-bcpio',
'bin' => 'application/octet-stream',
'bmp' => 'image/bmp',
'cdf' => 'application/x-netcdf',
'cgm' => 'image/cgm',
'class' => 'application/octet-stream',
'cpio' => 'application/x-cpio',
'cpt' => 'application/mac-compactpro',
'csh' => 'application/x-csh',
'css' => 'text/css',
'dcr' => 'application/x-director',
'dif' => 'video/x-dv',
'dir' => 'application/x-director',
'djv' => 'image/vnd.djvu',
'djvu' => 'image/vnd.djvu',
'dll' => 'application/octet-stream',
'dmg' => 'application/octet-stream',
'dms' => 'application/octet-stream',
'doc' => 'application/msword',
'dtd' => 'application/xml-dtd',
'dv' => 'video/x-dv',
'dvi' => 'application/x-dvi',
'dxr' => 'application/x-director',
'eps' => 'application/postscript',
'etx' => 'text/x-setext',
'exe' => 'application/octet-stream',
'ez' => 'application/andrew-inset',
'flv' => 'video/x-flv',
'gif' => 'image/gif',
'gram' => 'application/srgs',
'grxml' => 'application/srgs+xml',
'gtar' => 'application/x-gtar',
'gz' => 'application/x-gzip',
'hdf' => 'application/x-hdf',
'hqx' => 'application/mac-binhex40',
'htm' => 'text/html',
'html' => 'text/html',
'ice' => 'x-conference/x-cooltalk',
'ico' => 'image/x-icon',
'ics' => 'text/calendar',
'ief' => 'image/ief',
'ifb' => 'text/calendar',
'iges' => 'model/iges',
'igs' => 'model/iges',
'jnlp' => 'application/x-java-jnlp-file',
'jp2' => 'image/jp2',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'js' => 'application/x-javascript',
'kar' => 'audio/midi',
'latex' => 'application/x-latex',
'lha' => 'application/octet-stream',
'lzh' => 'application/octet-stream',
'm3u' => 'audio/x-mpegurl',
'm4a' => 'audio/mp4a-latm',
'm4p' => 'audio/mp4a-latm',
'm4u' => 'video/vnd.mpegurl',
'm4v' => 'video/x-m4v',
'mac' => 'image/x-macpaint',
'man' => 'application/x-troff-man',
'mathml' => 'application/mathml+xml',
'me' => 'application/x-troff-me',
'mesh' => 'model/mesh',
'mid' => 'audio/midi',
'midi' => 'audio/midi',
'mif' => 'application/vnd.mif',
'mov' => 'video/quicktime',
'movie' => 'video/x-sgi-movie',
'mp2' => 'audio/mpeg',
'mp3' => 'audio/mpeg',
'mp4' => 'video/mp4',
'mpe' => 'video/mpeg',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mpga' => 'audio/mpeg',
'ms' => 'application/x-troff-ms',
'msh' => 'model/mesh',
'mxu' => 'video/vnd.mpegurl',
'nc' => 'application/x-netcdf',
'oda' => 'application/oda',
'ogg' => 'application/ogg',
'ogv' => 'video/ogv',
'pbm' => 'image/x-portable-bitmap',
'pct' => 'image/pict',
'pdb' => 'chemical/x-pdb',
'pdf' => 'application/pdf',
'pgm' => 'image/x-portable-graymap',
'pgn' => 'application/x-chess-pgn',
'pic' => 'image/pict',
'pict' => 'image/pict',
'png' => 'image/png',
'pnm' => 'image/x-portable-anymap',
'pnt' => 'image/x-macpaint',
'pntg' => 'image/x-macpaint',
'ppm' => 'image/x-portable-pixmap',
'ppt' => 'application/vnd.ms-powerpoint',
'ps' => 'application/postscript',
'qt' => 'video/quicktime',
'qti' => 'image/x-quicktime',
'qtif' => 'image/x-quicktime',
'ra' => 'audio/x-pn-realaudio',
'ram' => 'audio/x-pn-realaudio',
'ras' => 'image/x-cmu-raster',
'rdf' => 'application/rdf+xml',
'rgb' => 'image/x-rgb',
'rm' => 'application/vnd.rn-realmedia',
'roff' => 'application/x-troff',
'rtf' => 'text/rtf',
'rtx' => 'text/richtext',
'sgm' => 'text/sgml',
'sgml' => 'text/sgml',
'sh' => 'application/x-sh',
'shar' => 'application/x-shar',
'silo' => 'model/mesh',
'sit' => 'application/x-stuffit',
'skd' => 'application/x-koan',
'skm' => 'application/x-koan',
'skp' => 'application/x-koan',
'skt' => 'application/x-koan',
'smi' => 'application/smil',
'smil' => 'application/smil',
'snd' => 'audio/basic',
'so' => 'application/octet-stream',
'spl' => 'application/x-futuresplash',
'src' => 'application/x-wais-source',
'sv4cpio' => 'application/x-sv4cpio',
'sv4crc' => 'application/x-sv4crc',
'svg' => 'image/svg+xml',
'swf' => 'application/x-shockwave-flash',
't' => 'application/x-troff',
'tar' => 'application/x-tar',
'tcl' => 'application/x-tcl',
'tex' => 'application/x-tex',
'texi' => 'application/x-texinfo',
'texinfo' => 'application/x-texinfo',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
'tr' => 'application/x-troff',
'tsv' => 'text/tab-separated-values',
'txt' => 'text/plain',
'ustar' => 'application/x-ustar',
'vcd' => 'application/x-cdlink',
'vrml' => 'model/vrml',
'vxml' => 'application/voicexml+xml',
'wav' => 'audio/x-wav',
'wbmp' => 'image/vnd.wap.wbmp',
'wbxml' => 'application/vnd.wap.wbxml',
'webm' => 'video/webm',
'wml' => 'text/vnd.wap.wml',
'wmlc' => 'application/vnd.wap.wmlc',
'wmls' => 'text/vnd.wap.wmlscript',
'wmlsc' => 'application/vnd.wap.wmlscriptc',
'wmv' => 'video/x-ms-wmv',
'wrl' => 'model/vrml',
'xbm' => 'image/x-xbitmap',
'xht' => 'application/xhtml+xml',
'xhtml' => 'application/xhtml+xml',
'xls' => 'application/vnd.ms-excel',
'xml' => 'application/xml',
'xpm' => 'image/x-xpixmap',
'xsl' => 'application/xml',
'xslt' => 'application/xslt+xml',
'xul' => 'application/vnd.mozilla.xul+xml',
'xwd' => 'image/x-xwindowdump',
'xyz' => 'chemical/x-xyz',
'zip' => 'application/zip'
);
return isset($mime_types[$ext]) ? $mime_types[$ext] : 'application/octet-stream';
}
~~~
/**
* 表格轉換數組
* @param $table 表格html代碼
* @return array
*/
~~~
function tableArr($table)
{
$table = preg_replace("'<table[^>]*?>'si", "", $table);
$table = preg_replace("'<tr[^>]*?>'si", "", $table);
$table = preg_replace("'<td[^>]*?>'si", "", $table);
$table = str_replace("</tr>", "{tr}", $table);
$table = str_replace("</td>", "{td}", $table);
//去掉 HTML 標記
$table = preg_replace("'<[/!]*?[^<>]*?>'si", "", $table);
//去掉空白字符
$table = preg_replace("'([rn])[s]+'", "", $table);
$table = preg_replace('/ /', "", $table);
$table = str_replace(" ", "", $table);
$table = str_replace(" ", "", $table);
$table = explode('{tr}', $table);
array_pop($table);
foreach ($table as $key => $tr) {
$td = explode('{td}', $tr);
array_pop($td);
$td_array[] = $td;
}
return $td_array;
}
~~~
刪除文件或文件夾,文件夾遞歸刪除,非常危險
~~~
function fileDelete($file){
if (empty($file))
return false;
if (@is_file($file))
return @unlink($file);
$ret = true;
if ($handle = @opendir($file)) {
while ($filename = @readdir($handle)){
if ($filename == '.' || $filename == '..')
continue;
if (!fileDelete($file . '/' . $filename))
$ret = false;
}
} else {
$ret = false;
}
@closedir($handle);
if ( file_exists($file) && !rmdir($file) ){
$ret = false;
}
return $ret;
}
~~~
/**
* 生成avatar頭像
* @param 郵箱 $email
* @param 大小 $s
* @param undefined $d
* @param undefined $g
*
* @return
*/
~~~
function getAvatar($email='', $s=40, $d='mm', $g='g') {
$hash = md5($email);
$avatar = "http://www.gravatar.com/avatar/$hash?s=$s&d=$d&r=$g";
return $avatar;
}
~~~
/**
* 加密解密函數
* ENCODE 加密
* @param $string
* @param string $operation
* @param string $key
* @param int $expiry
* @return string
*/
~~~
if (!function_exists('authcode')) {
function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0)
{
$ckey_length = 4;
$keya = md5(substr($key, 0, 16));
$keyb = md5(substr($key, 16, 16));
$keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length) : substr(md5(microtime()), -$ckey_length)) : '';
$cryptkey = $keya . md5($keya . $keyc);
$key_length = strlen($cryptkey);
$string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $keyb), 0, 16) . $string;
$string_length = strlen($string);
$result = '';
$box = range(0, 255);
$rndkey = array();
for ($i = 0; $i <= 255; $i++) {
$rndkey[$i] = ord($cryptkey[$i % $key_length]);
}
for ($j = $i = 0; $i < 256; $i++) {
$j = ($j + $box[$i] + $rndkey[$i]) % 256;
$tmp = $box[$i];
$box[$i] = $box[$j];
$box[$j] = $tmp;
}
for ($a = $j = $i = 0; $i < $string_length; $i++) {
$a = ($a + 1) % 256;
$j = ($j + $box[$a]) % 256;
$tmp = $box[$a];
$box[$a] = $box[$j];
$box[$j] = $tmp;
$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
}
if ($operation == 'DECODE') {
if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $keyb), 0, 16)) {
return substr($result, 26);
} else {
return '';
}
} else {
return $keyc . str_replace('=', '', base64_encode($result));
}
}
}
~~~
//百度地圖根據ip獲取經緯度,國家省市縣 城市代碼
~~~
function get_baidumap($ip="117.81.149.14",$ak="M4eExM3AxIcxOdnFGciErtK3"){
$d = get("https://api.map.baidu.com/location/ip?ak=$ak&coor=bd09ll&ip=$ip");
$d = json_decode($d,1);
$d = array(
"lon"=>$d['content']['point']['x'],
"lat"=>$d['content']['point']['y'] ,
"nation" => "中國",
"province" => $d['content']['address_detail']['province'],
"city" => $d['content']['address_detail']['city'],
"district" => $d['content']['address_detail']['district'],
"citycode" => $d['content']['address_detail']['city_code'] ,
"ip"=> $ip
);
return $d;
}
~~~
//qq地圖根據ip獲取經緯度,國家省市縣區號
~~~
function get_qqmap($ip="117.80.91.208",$ak="ACEBZ-FDXWP-WFRDV-VGS5Q-S2Q5K-HQBNA"){
$d = get("https://apis.map.qq.com/ws/location/v1/ip?ip=$ip&key=$ak");
$d = json_decode($d,1);
$d = array(
"lon"=>$d['result']['location']['lng'],
"lat"=>$d['result']['location']['lat'] ,
"nation" => $d['result']['ad_info']['nation'],
"province" => $d['result']['ad_info']['province'],
"city" => $d['result']['ad_info']['city'],
"district" => $d['result']['ad_info']['district'],
"adcode" => $d['result']['ad_info']['adcode'] ,
"ip"=> $d['result']['ip']
);
return $d;
}
~~~
//百度天氣接口 輸入城市或經緯度
~~~
function get_weather($city="昆山",$ak="M4eExM3AxIcxOdnFGciErtK3"){
$d = get("http://api.map.baidu.com/telematics/v3/weather?location=$city&output=json&ak=$ak");
$d = json_decode($d,1);
if($d['error']==0){
$d = array(
"date"=>$d['date'],
"city"=>$d['results'][0]['currentCity'],
"pm25"=>$d['results'][0]['pm25'], //pm
"index"=>$d['results'][0]['index'], //指數
"weather_data"=>$d['results'][0]['weather_data'], //當天,3天天氣
);
}else{
$d = array();
}
return $d;
}
~~~
高德天氣和ip定位
~~~
function getwether($ak='6812110e232abd4f53d345bed23a90d3',$ip='114.218.66.167'){
$url = "https://restapi.amap.com/v3/ip?key=$ak&ip=$ip";
$arr = json_decode(get($url),1);
$code = $arr['adcode'];//城市代碼
$json = get("https://restapi.amap.com/v3/weather/weatherInfo?key=$ak&city=$code&extensions=all");
$json = json_decode($json,1);
dump($json);
}
星座函數
function get_cons($month,$day){
if($month<1||$month>12||$day<1||$day>31) return false;
$constellations=array(
array("20"=>"寶瓶座"),
array("19"=>"雙魚座"),
array("21"=>"白羊座"),
array("20"=>"金牛座"),
array("21"=>"雙子座"),
array("22"=>"巨蟹座"),
array("23"=>"獅子座"),
array("23"=>"處女座"),
array("23"=>"天秤座"),
array("24"=>"天蝎座"),
array("22"=>"射手座"),
array("22"=>"摩羯座")
);
list($constellation_start,$constellation_name)=each($constellations[(int)$month-1]);
if($day<$constellation_start){
list($constellation_start,$constellation_name)=each($constellations[($month-2<0)?$month=11:$month-=2]);
}
return $constellation_name;
}
~~~
- 簡介
- 第一章 數據庫
- Mysql/mariadb
- 函數
- 基礎
- 增刪改索引
- 標準查詢
- 高級查詢
- TIDB集群mysql解決方案
- Redis
- 語言基礎
- 5種數據類型
- 其他類型
- Sqlite
- 語言基礎
- 常用查詢
- 第二章 PHP
- 語言基礎
- 第一課 流程控制和運算
- 第二課 數組
- 第三課 日期時間
- 第四課 常用函數
- 第五課 字符串
- 第六課 文件操作
- 第七課 面向對象
- 第八課 正則表達式
- 第九課 圖片處理生成
- 第十課 curl/memche
- 第十一課 mysql和pdo
- 第十三課 cookie和session
- 第十四課 xml操作
- 第十五課 php5.3+新特性
- 第十六課 php7+
- 第十七課 密碼安全
- 廢棄函數
- php命令行
- redis應用
- 算法
- 排序算法
- 基礎算法
- 無限級分類
- 自定義函數Fn
- 查找算法
- 自定義函數數據函數fn
- laravel
- 路由
- 常用語句
- 數據庫
- dingo/api
- Yii2
- 控制器
- 常用類
- 數據庫
- redis
- thinkphp6
- TP6文檔
- TP6插件
- dedecms
- 織夢標簽大全
- 數據庫操作
- 內置函數和定義函數
- 織夢核心改動
- 織夢插件/底層標簽開發
- PHP相關工具
- composer
- php開發環境phpenv
- Phpstorm使用
- windows編譯php擴展
- PHP開源庫
- 開源項目管理禪道
- sns_auth
- php-casbin權限控制
- php-jwt
- 微信SDKeasywechat
- querylist采集庫
- workerman
- Box/Spout處理excel和csv
- dll擴展
- redis/memche/xdebug
- redis
- Lua
- php_xlswriter
- event
- swoole
- 常用代碼庫
- 微擎框架
- 第一課全局變量
- 第二課常用函數
- 第三課自定義微擎獨有函數
- 第四課數據庫操作
- 第五課微信端回復
- 第六課微擎高級操作
- 第八課global函數列表
- mainfest.xml詳解
- js方法
- 人人商城
- 第一課model解讀
- 第二課常用語句解讀
- 第三課常用js解讀
- 第四課附錄常見問題
- 第五課附錄處理報表|支付
- 常用JSON狀態碼
- 第三章 JavaScript
- js基礎
- 瀏覽器對象
- 語言基礎
- html5接口
- ES6新語法
- vue
- 基礎語法
- 京東vueUI組件
- uniapp
- 組件開發規范
- nodejs
- 基礎知識
- 安裝node
- nvm不同版本node切換
- js常用標準庫
- zepto/jquery
- weui
- js圖標庫
- elementUI
- validator表單驗證
- layer彈出層
- requirejs
- wow動畫
- 動畫animate
- swiper4
- 百度編輯器
- flyio/axios/qs
- jquery.form
- bootstrap3
- clipboard復制
- slideout側滑
- imagehover.css圖片懸停動畫
- webpack打包
- Bulma UI框架
- store 客戶端存儲
- lottie動畫創建庫
- sweetalert
- js自定義函數
- 常見JSSDK
- 微信公眾號JSSDK
- 騰訊地圖jssdk
- 微信小程序
- 第四章 編程語言
- markdown語言
- Dart語言
- Dart語言基礎
- Flutter框架
- Lua語言
- 字符串,數組,表
- 自定義方法
- go語言
- 第1.1語言基本語法
- 第1.2流程控制
- 第1.3函數
- 第1.4結構體
- 第1.5接口
- 第1.6包
- go語言框架Gin
- CSS3語言
- CSS與CSS3
- 選擇符
- 屬性
- css3
- loading動畫
- HTML5語言
- less
- sass
- C#
- 基礎知識
- 函數
- 第五章 開發工具
- git
- nginx/apache服務器
- Linux常用操作
- crontab定時任務
- 注冊表與cmd
- 阿里云ECS
- frp穿透和ssl續期
- 寶塔安裝
- 樹莓派
- 瀏覽器模擬
- 火狐/chrome常用插件
- WSL安裝使用
- mac brew和終端命令
- win10相關