保存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相关