首页
关于小站
朋友
壁纸
留言
时光之书
笔顺字帖
LayUI手册
Search
1
【PHP】PHPoffice/PHPSpreadsheet读取和写入Excel
1,673 阅读
2
【Layui】控制页面元素展示隐藏
1,520 阅读
3
【Git】No tracked branch configured for branch master or the branch doesn't exist.
1,460 阅读
4
【PHP】PHP实现JWT生成和验证
1,370 阅读
5
精准检测,助力社交管理 —— 微信好友检测服务来袭!
1,278 阅读
默认分类
PHP
ThinkPHP
Laravel
面向对象
设计模式
算法
基础
网络安全
Web
HTML
CSS
JavaScript
jQuery
Layui
VUE
uni-app
Database
MySQL
Redis
RabbitMQ
Nginx
Git
Linux
Soft Ware
Windows
网赚
Go
Docker
登录
Search
标签搜索
PHP
函数
方法
类
MySQL
ThinkPHP
JavaScript
OOP
Layui
Web
Server
Docker
Linux
PHPSpreadsheet
PHPoffice
Array
设计模式
Git
排序算法
基础
小破孩
累计撰写
244
篇文章
累计收到
13
条评论
首页
栏目
默认分类
PHP
ThinkPHP
Laravel
面向对象
设计模式
算法
基础
网络安全
Web
HTML
CSS
JavaScript
jQuery
Layui
VUE
uni-app
Database
MySQL
Redis
RabbitMQ
Nginx
Git
Linux
Soft Ware
Windows
网赚
Go
Docker
页面
关于小站
朋友
壁纸
留言
时光之书
笔顺字帖
LayUI手册
搜索到
151
篇与
的结果
2022-06-21
【PHP】生成avatar头像
/** * @Author: 小破孩嫩 * @Email: 3584685883@qq.com * @Time: 2020/12/10 20:00 * @param string $email 邮箱 * @param int $s 大小 * @param string $d * @param string $g * @return string * @Description:生成avatar头像 */ 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; }
2022年06月21日
251 阅读
0 评论
0 点赞
2022-06-21
【PHP】获取文件MIME类型-根据文件扩展名来获取
function getFileType($ext){ static $mime_types = [ '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'; }
2022年06月21日
297 阅读
0 评论
0 点赞
2022-06-21
【PHP】ThinkPHP6 基本操作
请求变量 use think\facade\Request; Request::param('name'); Request::param();全部请求变量 返回数组 Request::param(['name', 'email']); 多个变量 Request::param('a','1') $a不存在使用默认值1 Request::param('username','','strip_tags'); 参数过滤 去掉html标签 htmlspecialchars转换成实体入库 strtolower小写 Request::header(); 请求头数组,支持单个 cookie input("name"); Request::session();获取 $_SESSION 变量 Request::cookie();获取 $_COOKIE 变量 Request::server();获取 $_SERVER 变量 Request::env();返回env数组 Request::file();获取 $_FILES 变量 Request::baseUrl(); /index/index Request::host(true); 域名:www.baidu.com,默认无参数包含端口:80 Request::url(1); 完整域名和地址 http://tp6.api.shanliwawa.top:80/index/index Request::domain(1) http://tp6.api.shanliwawa.top Request::time() 请求时间戳 Request::app() 应用名 index Request::controller() 控制器 Index 参数true小写 Request::action() 操作 index 参数true 小写 Request::method(true); 请求类型获取 GET isGet isPost isPut isDelete isAjax isMobile isHead 判断是否某种类型 Request::has('id','get'); 检测变量id是否存在 url('index/hello', ['id'=>5,'name'=>'李白'],'do'); http://tp6.api.shanliwawa.top/index/hello/李白.do?id=5 url('index/hello#aa'); 锚点 Cache::set('name', $value, 3600); 1小时后过期 Cache::get('name'); 获取缓存 多缓存类型配置 return [ // 缓存类型为File 'type' => 'redis', // 全局缓存有效期(0为永久有效) ,开发下一定要设置-1 否在刷新后 还在 'expire'=> -1, // 缓存前缀 'prefix'=> 'think', // 缓存目录 'host' => '127.0.0.1', ]; return [ // 使用复合缓存类型 'type' => 'complex', // 默认使用的缓存 'default' => [ // 驱动方式 'type' => 'file', // 缓存保存目录 'path' => '../runtime/default', ], // 文件缓存 'file' => [ // 驱动方式 'type' => 'file', // 设置不同的缓存保存目录 'path' => '../runtime/file/', ], // redis缓存 'redis' => [ // 驱动方式 'type' => 'redis', // 服务器地址 'host' => '127.0.0.1', ], ]; use think\facade\Cache; Cache::store('file')->set('name','123',0); $v = Cache::store('redis')->get('name'); Cache::store('default')->get('name');文件缓存 Cache::delete('name'); Cache::clear(); Cache::set('name', [1,2,3]); Cache::push('name', 4); Cache::remember('start_time', time()); 不存在则创建 Cache::inc('name',1); 自增1 Cache::dec('name',1); 自减1 $redis = Cache::handler(); redis对象 配置redis session return [ 'type' => 'redis', 'prefix' => 'think', 'auto_start' => true, // redis主机 'host' => '127.0.0.1', // redis端口 'port' => 6379, // 密码 'password' => '', ] session('name', ['thinkphp']); 设置支持字符串 数组 session('name');获取 session('name', null);删除 session(null);清空 cookie('name', 'value', 3600); 设置不支持数组,序列化后存储 cookie('name'); cookie('name', null); cookie('think_lang','en-us');//设置语言类型 lang('add user error');//翻译 config('cache.type') 读取配置 验证 {:token_field()} 模板中输出令牌 {:token_meta()} ajax提交 $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') } }); Route::post('blog/save','blog/save')->token(); 路由中使用验证 think\facade\Validate $rule = [ 'name' => 'require|max:25', 'age' => 'number|between:1,120', 'email' => 'email', ]; $msg = [ 'name.require' => '名称必须', 'name.max' => '名称最多不能超过25个字符', 'age.number' => '年龄必须是数字', 'age.between' => '年龄只能在1-120之间', 'email' => '邮箱格式错误', ]; $data = [ 'name' => 'thinkphp', 'age' => 10, 'email' => 'thinkphp@qq.com', ]; $validate = Validate::rule($rule)->message($msg); $result = $validate->check($data); if(!$result) { dump($validate->getError()); } 路由 Route::get('new/<id>','News/read'); // 定义GET请求路由规则 Route::post('new/<id>','News/update'); // 定义POST请求路由规则 Route::put('new/:id','News/update'); // 定义PUT请求路由规则 Route::delete('new/:id','News/delete'); // 定义DELETE请求路由规则 Route::any('new/:id','News/read'); // 所有请求都支持的路由规则 ->allowCrossDomain();跨域 输出响应 $data=['code'=>200,'msg'=>'信息提示','list'=>['中国']]; json($data); jsonp($data); xml($data); redirect('http://www.thinkphp.cn'); redirect('/index/hello/name'); //站内跳转 download('./static/2.xlsx'); 下载 数据库 use think\facade\Db; $rs =Db::name('user')->where('id',1)->find(); 查询一条记录 name不含前缀 $rs =Db::table('ims_user')->where('sex', 2)->select(); 多条数据 table含前缀 $rs1 =Db::name('user')->where('id', 1)->value('name'); 查询某个字段值 $rs =Db::table('ims_user')->where('sex', 2)->column('name,id','id'); 返回name,id列,后面是key $userId = Db::name('user')->insertGetId($data);//插入数据返回id Db::name('user') ->limit(100) ->insertAll($data); 插入多条数据,分每次100 Db::name('user') ->where('id', 1) ->update(['name' => 'thinkphp']); 更新 Db::table('think_user')->delete(1); Db::table('think_user')->delete([1,2,3]); Db::table('think_user')->where('id',1)->delete(); Db::name('user')->delete(true);//清空数据 where('id','<>',1) 不等于1 > >= like where("id=:id and username=:name", ['id' => 1 , 'name' => 'thinkphp']) field('id,title,content') 指定字段 limit(10,25) 第十条开始25条 单数字返回数据条数 page(1,10) 第一页十条 order(['id'=>'desc','sex'=>'desc']) 排序 group('user_id,test_time') 分组 count() max('id') min() avg() sum() 聚合函数 whereTime('birthday', '>=', '1970-10-1') 支持< = whereTime('create_time','-2 hours') 查询2小时 whereBetweenTime('create_time', '2017-01-01', '2017-06-30') 查询时间段 whereYear('create_time') 今年 whereYear('create_time','2018') last year 去年 whereMonth('create_time') last month上月 2018-06 具体月份 whereWeek('create_time') last week 上周 whereDay('create_time')今天 yesterday昨天 2018-11-1具体 Db::query("select * from think_user where status=1"); 原生查询 Db::execute("update think_user set name='thinkphp' where status=1");//更新插入删除 Db::query("select * from think_user where id=? AND status=?", [8, 1]);//绑定 $list = Db::name('user')->where('status',1)->paginate(10); 分页每页10条 模型 定义全局常量 define('__URL__',\think\facade\Request::domain(1)); http://tp6.api.shanliwawa.top define('__ROOT__',\think\facade\app::getRootPath()); 系统根目录 C:\www\tp6\ define("PRE",config('database.prefix')); 表前缀 绝对路径获取 \think\facade\app::getRootPath() 根目录C:\www\tp6\ \think\facade\app::getAppPath() 应用路径 C:\www\tp6\app\index\ \think\facade\app::getConfigPath() 配置路径C:\www\tp6\config\ \think\facade\app::version() 核心版本 模板视图 use think\facade\View; View::assign([ 'name' => 'ThinkPHP', 'email' => 'thinkphp@qq.com' ]); View::assign('data',[ 'name' => 'ThinkPHP', 'email' => 'thinkphp@qq.com' ]); View::fetch('index'); 助手函数 view('index', [ 'name' => 'ThinkPHP', 'email' => 'thinkphp@qq.com' ]); 模板输出 {$name} {$data.name} 等价 {$data['name']} {:dump($data)} 使用函数 :开头 {$user.nickname|default="这家伙很懒,什么也没留下"} {$Think.cookie.name} // 输出$_COOKIE['name']变量 {$Think.server.script_name} // 输出$_SERVER['SCRIPT_NAME']变量 {$Think.session.user_id} // 输出$_SESSION['user_id']变量 {$Think.get.page} // 输出$_GET['page']变量 {$Request.param.name} 获取name {$data.name|raw} 不转义输出 {$data.create_time|date='Y-m-d H:i'} {literal} Hello,{$name}! 原样输出 {/literal} {load href="/static/js/common.js,/static/js/common.css" /} 加载js,css {php}echo 'Hello,world!';{/php} {/* 注释内容 */ } 或 {// 注释内容 } {include file="public/header" /} 模板包含 {include file="Public/header" title="$title" keywords="开源WEB开发框架" /} 传入参数 {foreach $list as $key=>$vo } {$vo.id}:{$vo.name} {/foreach} {for start="开始值" end="结束值" comparison="" step="步进值" name="循环变量名" } {/for} {if 表达式}value1 {elseif 表达式 /}value2 {else /}value3 {/if} 记录日志 log.php 可添加 'json' => 1 表示json格式 trace("日志信息") app.php中 'app_trace' => true, trace.php改为默认html 'type' => 'Console', 上传 $file = request()->file('image'); 移动到框架应用根目录/uploads/ 目录下 $info = $file->move( '../uploads'); if($info){ 成功上传后 获取上传信息 输出 jpg echo $info->getExtension(); 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg echo $info->getSaveName(); 输出 42a79759f284b767dfcb2a0197904287.jpg echo $info->getFilename(); }else{ 上传失败获取错误信息 echo $file->getError(); } 多文件xphr foreach($files as $file){} 验证,生成带md5文件名 $info = $file->rule('md5')->validate(['size'=>15678,'ext'=>'jpg,png,gif'])->move( '../uploads');
2022年06月21日
298 阅读
0 评论
0 点赞
2022-06-21
【PHP】ThinkPHP5 实现sentry通知,记录日志
<?php namespace app\index\common; use think\Log; class Logs { //sentry日志收集器 static public function sentryLogs($e,$line,array $data = []) { Log::init([ 'type' => 'File', 'path' => LOG_PATH, ]); $sentryClient = new \Raven_Client( 'https://c5485e6c233347ca8a7990a2bf77514a:9a69f3eb68c446f8ae3247eb368c1ff6@sentry.io/1193480', [ 'name' => \Raven_Compat::gethostname(),//服务器主机名 'environment' => 'production', 'level' => 'error', //附加数据 'extra' => $data, 'app_path' => ROOT_PATH, 'sample_rate' => 1,//值0.00将拒绝发送任何事件,值1.00将发送100%的事件。 'curl_method' => 'async',//curl异步发送,比同步体验好很多 //回掉方法,在发送数据之前操作 'send_callback' => function ($data) { }, ]); //单独设置用户信息 $sentryClient->user_context([ 'id' => 2966, 'username' => 'XPH', 'email' => '3584685883@qq.com', 'mobile' => '176****376', 'ip_address' => $_SERVER['REMOTE_ADDR'] ]); if ( $e && is_object($e) ) { $sentryClient->captureException($e); $errorMsg = "\n文件:".$e->getFile()."\n行数:".$e->getLine()."\n错误代码:".$e->getCode()."\n错误信息:".$e->getMessage()."\n"; }else{ //当没有异常只想记录信息的时候可以使用这个 $sentryClient->captureMessage($e); $errorMsg = $e."\n行数:".$line; } Log::record($errorMsg); } }
2022年06月21日
267 阅读
0 评论
0 点赞
2022-06-21
【PHP】好用的PHP函数集合-在线版
string函数:http://www.w3school.com.cn/php/php_ref_string.asp array函数:http://www.w3school.com.cn/php/php_ref_array.asp 日期函数:http://www.w3school.com.cn/php/php_ref_date.asp 日历函数:http://www.w3school.com.cn/php/php_ref_calendar.asp 目录函数:http://www.w3school.com.cn/php/php_ref_directory.asp 数学函数:http://php.net/manual/zh/ref.math.php
2022年06月21日
260 阅读
0 评论
0 点赞
2022-06-19
【PHP】PHP实现驼峰转下划线
function to_slash($array) { // 先转成json字符串,进行正则替换,再转换为数组 $tmp = json_encode($array); $tmp = strtolower(preg_replace('/((?<=[a-z])(?=[A-Z]))/', '_', $tmp)); $tmp = json_decode($tmp, true); return $tmp; } 原理: // 驼峰转下划线 // 先添加分隔符,再转成小写 // userId => user_id $str = preg_replace('/((?<=[a-z])(?=[A-Z]))/','_',$str); $str = strtolower($str); // 下划线转驼峰 // 同样先添加分隔符,再转成大写 // user_id => userId $array = explode('_',$str); array_walk($array,create_function('&$v','$v=ucwords($v);')); $str = implode('',$array); // 首字母转小写 $str{0} = strtolower($str{0})
2022年06月19日
141 阅读
0 评论
0 点赞
2022-06-19
【PHP】PHP地理位置计算
<?php /** *求两个已知经纬度之间的距离,单位为米 *@param lng1,lng2 经度 *@param lat1,lat2 纬度 *@return float 距离,单位米 **/ function getdistance($lng1,$lat1,$lng2,$lat2){ //将角度转为狐度 $radLat1=deg2rad($lat1);//deg2rad()函数将角度转换为弧度 $radLat2=deg2rad($lat2); $radLng1=deg2rad($lng1); $radLng2=deg2rad($lng2); $a=$radLat1-$radLat2; $b=$radLng1-$radLng2; $s=2*asin(sqrt(pow(sin($a/2),2)+cos($radLat1)*cos($radLat2)*pow(sin($b/2),2)))*6378.137*1000; return intval($s); } function distanceConvert($s){ $s = intval($s); if($s <= 0){ return '附近'; }elseif($s > 0 && $s <= 1000){ return $s.'m'; }elseif($s > 1000 && $s <= 2000){ return '<2km'; }elseif($s > 2000 && $s <= 3000){ return '<3km'; }elseif($s > 3000 && $s <= 4000){ return '<4km'; }elseif($s > 4000 && $s <= 5000){ return '<5km'; }elseif($s > 5000){ return '>5km'; } } /** * 根据条件获取商户列表 * @param string $lng * @param string $lat * @param string $city_id * @param string $district_id * @param string $type_id * @param string $search * @return mixed */ //如果存在经纬度则考虑范围5公里内数据,如果不存在经纬度,则不考虑 public function GetShopList($navigationId = 0,$page = 1,$size =10 ,$lng = '', $lat ='', $city_id = '',$district_id = '',$type_id = '',$search = '') { $field = 'id,province_id,city_id,district_id,navigation_id,type_id,name,phone,address,logo,stime,etime,rule,activity,discount,latitude,longitude,status,token,sort,description,gmt_created'; $where = array( 'is_deleted' => 0, 'is_show' => 1, 'navigation_id'=>$navigationId, ); //判断城市,县区,分类是否存在 if(!empty($city_id)){ $where['city_id|province_id'] = $city_id; } if(!empty($district_id)){ $where['district_id'] = $district_id; } if(!empty($type_id)){ $where['type_id'] = $type_id; } if(!empty($search)){ $where['name'] = array('like',"%{$search}%"); } $offset = ($page * $size) - ($size - 1); //如果存在经纬度,就根据经纬度查询5公里范围内数据 if(!empty($lng) && !empty($lat)) { // //求出半径 // $radius = 5;//半径范围,单位km // $rangeLat = 180 / pi() * $radius / 6372.797;//纬度范围 // $rangeLng = $rangeLat / cos($lat * pi() / 180.0); //经度范围 // $maxLat = $lat + $rangeLat; //x1 // $minLat = $lat - $rangeLat; //x0 // $maxLng = $lng + $rangeLng; //y1 // $minLng = $lng - $rangeLng; //y0 // // $where['latitude'] = array(array('lt',$maxLat),array('gt',$minLat)); // $where['longitude'] = array(array('lt',$maxLng),array('gt',$minLng)); $list = $this->where($where)->field($field)->order("abs(longitude - {$lng}) + abs(latitude - {$lat})")->limit($offset,$size)->select(); }else{ $list = $this->where($where)->field($field)->order('sort asc')->limit($offset,$size)->select(); } //记录错误日志 if ($list === false) { wLog('GetShopList error! sql:' . $this->getLastSql(), $this->errorFile); wLog('GetShopList error! errorInfo:' . $this->error, $this->errorFile); } //wLog('GetShopList sql:' . $this->getLastSql(), $this->errorFile); return $list; }
2022年06月19日
225 阅读
0 评论
0 点赞
2022-06-19
【PHP】PHP原生生成EXCEL
<?php /*** * 生成excle文件 ***/ $time = time(); $filename = date("Y年m月d日h点m分s秒", $time).'问卷数据'; $rows = Sp_Looks_Vote::downvote(); $file = $filename.".csv"; header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); $tabletitle .= "购买地址,常常购买,喜欢模特,内容如何,印象如何,是否购买,感觉如何,购买方式,购买方式建议,吸引点,改进建议"; $conter = iconv('utf-8','gbk',$tabletitle)."\n"; echo $conter;die; /*** * 生成word文件 ***/ header("Content-Type: application/msword"); header("Content-Disposition: attachment; filename=doc.doc"); header("Pragma: no-cache"); header("Expires: 0"); $output = '<table border="1" cellspacing="2" cellpadding="2" width="90%" align="center">'; $output .= '<tr bgcolor="#cccccc"><td align="center">图片</td></tr>'; $output .= '<tr bgcolor="#f6f7fa"><td><span style="color:#FF0000;"><strong>下面是一张图片</strong></span& gt;</td></tr>'; $output .= '<tr><td align="center"><img src="http://zi.csdn.net/48260_2.gif"></td></tr>'; $output .= '</table>'; echo $output; ?>
2022年06月19日
293 阅读
0 评论
0 点赞
2022-06-19
【PHP】PHP的邮件发送类
<?php /** * 邮件发送类 * 支持发送纯文本邮件和HTML格式的邮件,可以多收件人,多抄送,多秘密抄送,带附件的邮件 * 需要的php扩展,sockets和Fileinfo。 * @example * $mail = new MySendMail(); * $mail->setServer("XXXXX", "XXXXX@XXXXX", "XXXXX"); 设置smtp服务器 * $mail->setFrom("XXXXX"); 设置发件人 * $mail->setReceiver("XXXXX"); 设置收件人,多个收件人,调用多次 * $mail->setCc("XXXX"); 设置抄送,多个抄送,调用多次 * $mail->setBcc("XXXXX"); 设置秘密抄送,多个秘密抄送,调用多次 * $mail->setMailInfo("test", "<b>test</b>"); 设置邮件主题、内容 * $mail->sendMail(); 发送 */ class MySendMail { /** * @var string 邮件传输代理用户名 * @access private */ private $_userName; /** * @var string 邮件传输代理密码 * @access private */ private $_password; /** * @var string 邮件传输代理服务器地址 * @access protected */ protected $_sendServer; /** * @var int 邮件传输代理服务器端口 * @access protected */ protected $_port=25; /** * @var string 发件人 * @access protected */ protected $_from; /** * @var string 收件人 * @access protected */ protected $_to; /** * @var string 抄送 * @access protected */ protected $_cc; /** * @var string 秘密抄送 * @access protected */ protected $_bcc; /** * @var string 主题 * @access protected */ protected $_subject; /** * @var string 邮件正文 * @access protected */ protected $_body; /** * @var string 附件 * @access protected */ protected $_attachment; /** * @var reource socket资源 * @access protected */ protected $_socket; /** * @var string 错误信息 * @access protected */ protected $_errorMessage; /** * 设置邮件传输代理,如果是可以匿名发送有邮件的服务器,只需传递代理服务器地址就行 * @access public * @param string $server 代理服务器的ip或者域名 * @param string $username 认证账号 * @param string $password 认证密码 * @param int $port 代理服务器的端口,smtp默认25号端口 * @return boolean */ public function setServer($server, $username="", $password="", $port=25) { $this->_sendServer = $server; $this->_port = $port; if(!empty($username)) { $this->_userName = base64_encode($username); } if(!empty($password)) { $this->_password = base64_encode($password); } return true; } /** * 设置发件人 * @access public * @param string $from 发件人地址 * @return boolean */ public function setFrom($from) { $this->_from = $from; return true; } /** * 设置收件人,多个收件人,连续调用多次. * @access public * @param string $to 收件人地址 * @return boolean */ public function setReceiver($to) { if(isset($this->_to)) { if(is_string($this->_to)) { $this->_to = array($this->_to); $this->_to[] = $to; return true; } elseif(is_array($this->_to)) { $this->_to[] = $to; return true; } else { return false; } } else { $this->_to = $to; return true; } } /** * 设置抄送,多个抄送,连续调用多次. * @access public * @param string $cc 抄送地址 * @return boolean */ public function setCc($cc) { if(isset($this->_cc)) { if(is_string($this->_cc)) { $this->_cc = array($this->_cc); $this->_cc[] = $cc; return true; } elseif(is_array($this->_cc)) { $this->_cc[] = $cc; return true; } else { return false; } } else { $this->_cc = $cc; return true; } } /** * 设置秘密抄送,多个秘密抄送,连续调用多次 * @access public * @param string $bcc 秘密抄送地址 * @return boolean */ public function setBcc($bcc) { if(isset($this->_bcc)) { if(is_string($this->_bcc)) { $this->_bcc = array($this->_bcc); $this->_bcc[] = $bcc; return true; } elseif(is_array($this->_bcc)) { $this->_bcc[] = $bcc; return true; } else { return false; } } else { $this->_bcc = $bcc; return true; } } /** * 设置邮件信息 * @access public * @param string $body 邮件主题 * @param string $subject 邮件主体内容,可以是纯文本,也可是是HTML文本 * @param string $attachment 附件,文件地址 * @return boolean */ public function setMailInfo($subject, $body, $attachment="") { $this->_subject = $subject; $this->_body = base64_encode($body); if(!empty($attachment)) { $this->_attachment = $attachment; } return true; } /** * 发送邮件 * @access public * @return boolean */ public function sendMail() { $command = $this->getCommand(); $this->socket(); foreach ($command as $value) { if($this->sendCommand($value[0], $value[1])) { continue; } else{ return false; } } //其实这里也没必要关闭,smtp命令:QUIT发出之后,服务器就关闭了连接,本地的socket资源会自动释放 $this->close(); echo 'Mail OK!'; return true; } /** * 返回错误信息 * @return string */ public function error(){ if(!isset($this->_errorMessage)) { $this->_errorMessage = ""; } return $this->_errorMessage; } /** * 返回mail命令 * @access protected * @return array */ protected function getCommand() { $command = array( array("HELO sendmail\r\n", 250) ); if(!empty($this->_userName)){ $command[] = array("AUTH LOGIN\r\n", 334); $command[] = array($this->_userName . "\r\n", 334); $command[] = array($this->_password . "\r\n", 235); } $command[] = array("MAIL FROM:<" . $this->_from . ">\r\n", 250); $separator = "----=_Part_" . md5($this->_from . time()) . uniqid(); //分隔符 //设置发件人 $header = "FROM: test<" . $this->_from . ">\r\n"; //设置收件人 if(is_array($this->_to)) { $count = count($this->_to); for($i=0; $i<$count; $i++){ $command[] = array("RCPT TO: <" . $this->_to[$i] . ">\r\n", 250); if($i == 0){ $header .= "TO: <" . $this->_to[$i] .">"; } elseif($i + 1 == $count){ $header .= ",<" . $this->_to[$i] .">\r\n"; } else{ $header .= ",<" . $this->_to[$i] .">"; } } } else{ $command[] = array("RCPT TO: <" . $this->_to . ">\r\n", 250); $header .= "TO: <" . $this->_to . ">\r\n"; } //设置抄送 if(isset($this->_cc)) { if(is_array($this->_cc)) { $count = count($this->_cc); for($i=0; $i<$count; $i++){ $command[] = array("RCPT TO: <" . $this->_cc[$i] . ">\r\n", 250); if($i == 0){ $header .= "CC: <" . $this->_cc[$i] .">"; } elseif($i + 1 == $count){ $header .= ",<" . $this->_cc[$i] .">\r\n"; } else{ $header .= ",<" . $this->_cc[$i] .">"; } } } else{ $command[] = array("RCPT TO: <" . $this->_cc . ">\r\n", 250); $header .= "CC: <" . $this->_cc . ">\r\n"; } } //设置秘密抄送 if(isset($this->_bcc)) { if(is_array($this->_bcc)) { $count = count($this->_bcc); for($i=0; $i<$count; $i++){ $command[] = array("RCPT TO: <" . $this->_bcc[$i] . ">\r\n", 250); if($i == 0){ $header .= "BCC: <" . $this->_bcc[$i] .">"; } elseif($i + 1 == $count){ $header .= ",<" . $this->_bcc[$i] .">\r\n"; } else{ $header .= ",<" . $this->_bcc[$i] .">"; } } } else{ $command[] = array("RCPT TO: <" . $this->_bcc . ">\r\n", 250); $header .= "BCC: <" . $this->_bcc . ">\r\n"; } } $header .= "Subject: " . $this->_subject ."\r\n"; if(isset($this->_attachment)) { //含有附件的邮件头需要声明成这个 $header .= "Content-Type: multipart/mixed;\r\n"; } elseif(false){ //邮件体含有图片资源的需要声明成这个 $header .= "Content-Type: multipart/related;\r\n"; } else{ //html或者纯文本的邮件声明成这个 $header .= "Content-Type: multipart/alternative;\r\n"; } //邮件头分隔符 $header .= "\t" . 'boundary="' . $separator . '"'; $header .= "\r\nMIME-Version: 1.0\r\n"; $header .= "\r\n--" . $separator . "\r\n"; $header .= "Content-Type:text/html; charset=utf-8\r\n"; $header .= "Content-Transfer-Encoding: base64\r\n\r\n"; $header .= $this->_body . "\r\n"; $header .= "--" . $separator . "\r\n"; //加入附件 if(isset($this->_attachment)){ $header .= "\r\n--" . $separator . "\r\n"; $header .= "Content-Type: " . $this->getMIMEType() . '; name="' . basename($this->_attachment) . '"' . "\r\n"; $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= 'Content-Disposition: attachment; filename="' . basename($this->_attachment) . '"' . "\r\n"; $header .= "\r\n"; $header .= $this->readFile(); $header .= "\r\n--" . $separator . "\r\n"; } $header .= "\r\n.\r\n"; $command[] = array("DATA\r\n", 354); $command[] = array($header, 250); $command[] = array("QUIT\r\n", 221); return $command; } /** * 发送命令 * @access protected * @param string $command 发送到服务器的smtp命令 * @param int $code 期望服务器返回的响应吗 * @return boolean */ protected function sendCommand($command, $code) { echo 'Send command:' . $command . ',expected code:' . $code . '<br />'; //发送命令给服务器 try{ if(socket_write($this->_socket, $command, strlen($command))){ //当邮件内容分多次发送时,没有$code,服务器没有返回 if(empty($code)) { return true; } //读取服务器返回 $data = trim(socket_read($this->_socket, 1024)); echo 'response:' . $data . '<br /><br />'; if($data) { $pattern = "/^".$code."/"; if(preg_match($pattern, $data)) { return true; } else{ $this->_errorMessage = "Error:" . $data . "|**| command:"; return false; } } else{ $this->_errorMessage = "Error:" . socket_strerror(socket_last_error()); return false; } } else{ $this->_errorMessage = "Error:" . socket_strerror(socket_last_error()); return false; } }catch(Exception $e) { $this->_errorMessage = "Error:" . $e->getMessage(); } } /** * 读取附件文件内容,返回base64编码后的文件内容 * @access protected * @return mixed */ protected function readFile() { if(isset($this->_attachment) && file_exists($this->_attachment)) { $file = file_get_contents($this->_attachment); return base64_encode($file); } else { return false; } } /** * 获取附件MIME类型 * @access protected * @return mixed */ protected function getMIMEType() { if(isset($this->_attachment) && file_exists($this->_attachment)) { $mime = mime_content_type($this->_attachment); if(! preg_match("/gif|jpg|png|jpeg/", $mime)){ $mime = "application/octet-stream"; } return $mime; } else { return false; } } /** * 建立到服务器的网络连接 * @access private * @return boolean */ private function socket() { if(!function_exists("socket_create")) { $this->_errorMessage = "Extension sockets must be enabled"; return false; } //创建socket资源 $this->_socket = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp')); if(!$this->_socket) { $this->_errorMessage = socket_strerror(socket_last_error()); return false; } socket_set_block($this->_socket);//设置阻塞模式 //连接服务器 if(!socket_connect($this->_socket, $this->_sendServer, $this->_port)) { $this->_errorMessage = socket_strerror(socket_last_error()); return false; } socket_read($this->_socket, 1024); return true; } /** * 关闭socket * @access private * @return boolean */ private function close() { if(isset($this->_socket) && is_object($this->_socket)) { $this->_socket->close(); return true; } $this->_errorMessage = "No resource can to be close"; return false; } } <?php /** * 邮件发送类 * 仅支持发送纯文本和HTML内容邮件 * 需要的php扩展,sockets * @example * $mail = new MySendMail(); * $mail->setServer("XXXXX", "XXXXX@XXXXX", "XXXXX"); 设置smtp服务器 * $mail->setFrom("XXXXX"); 设置发件人 * $mail->setReceiver("XXXXX"); 设置收件人 * $mail->setMailInfo("test", "<b>test</b>"); 设置邮件主题、内容 * $mail->sendMail(); 发送 */ class MySendMail2 { /** * @var string 邮件传输代理用户名 * @access private */ private $_userName; /** * @var string 邮件传输代理密码 * @access private */ private $_password; /** * @var string 邮件传输代理服务器地址 * @access private */ private $_sendServer; /** * @var int 邮件传输代理服务器端口 * @access protected */ protected $_port=25; /** * @var string 发件人 * @access protected */ protected $_from; /** * @var string 收件人 * @access protected */ protected $_to; /** * @var string 主题 * @access protected */ protected $_subject; /** * @var string 邮件正文 * @access protected */ protected $_body; /** * @var reource socket资源 * @access protected */ protected $_socket; /** * @var string 错误信息 * @access protected */ protected $_errorMessage; /** * 设置邮件传输代理,如果是可以匿名发送有邮件的服务器,只需传递代理服务器地址就行 * @access public * @param string $server 代理服务器的ip或者域名 * @param string $username 认证账号 * @param string $password 认证密码 * @param int $port 代理服务器的端口,smtp默认25号端口 * @return boolean */ public function setServer($server, $username="", $password="", $port=25) { $this->_sendServer = $server; $this->_port = $port; if(!empty($username)) { $this->_userName = base64_encode($username); } if(!empty($password)) { $this->_password = base64_encode($password); } return true; } /** * 设置发件人 * @access public * @param string $from 发件人地址 * @return boolean */ public function setFrom($from) { $this->_from = $from; return true; } /** * 设置收件人 * @access public * @param string $to 收件人地址 * @return boolean */ public function setReceiver($to) { $this->_to = $to; return true; } /** * 设置邮件信息 * @access public * @param string $body 邮件主题 * @param string $subject 邮件主体内容,可以是纯文本,也可是是HTML文本 * @return boolean */ public function setMailInfo($subject, $body) { $this->_subject = $subject; $this->_body = base64_encode($body); if(!empty($attachment)) { $this->_attachment = $attachment; } return true; } /** * 发送邮件 * @access public * @return boolean */ public function sendMail() { $command = $this->getCommand(); $this->socket(); foreach ($command as $value) { if($this->sendCommand($value[0], $value[1])) { continue; } else{ return false; } } //其实这里也没必要关闭,smtp命令:QUIT发出之后,服务器就关闭了连接,本地的socket资源会自动释放 $this->close(); echo 'Mail OK!'; return true; } /** * 返回错误信息 * @return string */ public function error(){ if(!isset($this->_errorMessage)) { $this->_errorMessage = ""; } return $this->_errorMessage; } /** * 返回mail命令 * @access protected * @return array */ protected function getCommand() { $separator = "----=_Part_" . md5($this->_from . time()) . uniqid(); //分隔符 $command = array( array("HELO sendmail\r\n", 250) ); if(!empty($this->_userName)){ $command[] = array("AUTH LOGIN\r\n", 334); $command[] = array($this->_userName . "\r\n", 334); $command[] = array($this->_password . "\r\n", 235); } //设置发件人 $command[] = array("MAIL FROM: <" . $this->_from . ">\r\n", 250); $header = "FROM: <" . $this->_from . ">\r\n"; //设置收件人 $command[] = array("RCPT TO: <" . $this->_to . ">\r\n", 250); $header .= "TO: <" . $this->_to . ">\r\n"; $header .= "Subject: " . $this->_subject ."\r\n"; $header .= "Content-Type: multipart/alternative;\r\n"; //邮件头分隔符 $header .= "\t" . 'boundary="' . $separator . '"'; $header .= "\r\nMIME-Version: 1.0\r\n"; $header .= "\r\n--" . $separator . "\r\n"; $header .= "Content-Type:text/html; charset=utf-8\r\n"; $header .= "Content-Transfer-Encoding: base64\r\n\r\n"; $header .= $this->_body . "\r\n"; $header .= "--" . $separator . "\r\n"; //结束数据 $header .= "\r\n.\r\n"; $command[] = array("DATA\r\n", 354); $command[] = array($header, 250); $command[] = array("QUIT\r\n", 221); return $command; } /** * 发送命令 * @access protected * @param string $command 发送到服务器的smtp命令 * @param int $code 期望服务器返回的响应吗 * @return boolean */ protected function sendCommand($command, $code) { echo 'Send command:' . $command . ',expected code:' . $code . '<br />'; //发送命令给服务器 try{ if(socket_write($this->_socket, $command, strlen($command))){ //当邮件内容分多次发送时,没有$code,服务器没有返回 if(empty($code)) { return true; } //读取服务器返回 $data = trim(socket_read($this->_socket, 1024)); echo 'response:' . $data . '<br /><br />'; if($data) { $pattern = "/^".$code."/"; if(preg_match($pattern, $data)) { return true; } else{ $this->_errorMessage = "Error:" . $data . "|**| command:"; return false; } } else{ $this->_errorMessage = "Error:" . socket_strerror(socket_last_error()); return false; } } else{ $this->_errorMessage = "Error:" . socket_strerror(socket_last_error()); return false; } }catch(Exception $e) { $this->_errorMessage = "Error:" . $e->getMessage(); } } /** * 建立到服务器的网络连接 * @access private * @return boolean */ private function socket() { if(!function_exists("socket_create")) { $this->_errorMessage = "Extension sockets must be enabled"; return false; } //创建socket资源 $this->_socket = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp')); if(!$this->_socket) { $this->_errorMessage = socket_strerror(socket_last_error()); return false; } socket_set_block($this->_socket);//设置阻塞模式 //连接服务器 if(!socket_connect($this->_socket, $this->_sendServer, $this->_port)) { $this->_errorMessage = socket_strerror(socket_last_error()); return false; } socket_read($this->_socket, 1024); return true; } /** * 关闭socket * @access private * @return boolean */ private function close() { if(isset($this->_socket) && is_object($this->_socket)) { $this->_socket->close(); return true; } $this->_errorMessage = "No resource can to be close"; return false; } } /**************************** Test ***********************************/ // $mail = new MySendMail(); // $mail->setServer("XXXX", "XXXXX@XXXXX", "XXXX"); // $mail->setFrom("XXXXX@XXXXX"); // $mail->setReceiver("XXXXX@XXXXX"); // $mail->setMailInfo("test", "<b>test</b>"); // $mail->sendMail(); ?>
2022年06月19日
264 阅读
0 评论
0 点赞
2022-06-19
【PHP】PHP获取汉字首个拼音
function getFirstChar($s0) { //ord() 函数返回字符串的首个字符的 ASCII 值 $fchar = ord($s0{0}); if ($fchar >= ord("A") and $fchar <= ord("z")) return strtoupper($s0{0}); $s1 = iconv("UTF-8", "gb2312", $s0); $s2 = iconv("gb2312", "UTF-8", $s1); if ($s2 == $s0) { $s = $s1; } else { $s = $s0; } $asc = ord($s{0}) * 256 + ord($s{1}) - 65536; if ($asc >= -20319 and $asc <= -20284) return "A"; if ($asc >= -20283 and $asc <= -19776) return "B"; if ($asc >= -19775 and $asc <= -19219) return "C"; if ($asc >= -19218 and $asc <= -18711) return "D"; if ($asc >= -18710 and $asc <= -18527) return "E"; if ($asc >= -18526 and $asc <= -18240) return "F"; if ($asc >= -18239 and $asc <= -17923) return "G"; if ($asc >= -17922 and $asc <= -17418) return "I"; if ($asc >= -17417 and $asc <= -16475) return "J"; if ($asc >= -16474 and $asc <= -16213) return "K"; if ($asc >= -16212 and $asc <= -15641) return "L"; if ($asc >= -15640 and $asc <= -15166) return "M"; if ($asc >= -15165 and $asc <= -14923) return "N"; if ($asc >= -14922 and $asc <= -14915) return "O"; if ($asc >= -14914 and $asc <= -14631) return "P"; if ($asc >= -14630 and $asc <= -14150) return "Q"; if ($asc >= -14149 and $asc <= -14091) return "R"; if ($asc >= -14090 and $asc <= -13319) return "S"; if ($asc >= -13318 and $asc <= -12839) return "T"; if ($asc >= -12838 and $asc <= -12557) return "W"; if ($asc >= -12556 and $asc <= -11848) return "X"; if ($asc >= -11847 and $asc <= -11056) return "Y"; if ($asc >= -11055 and $asc <= -10247) return "Z"; return null; } function chinesePhoneticize($zh) { $ret = ""; $s1 = iconv("UTF-8", "gb2312", $zh); $s2 = iconv("gb2312", "UTF-8", $s1); if ($s2 == $zh) { $zh = $s1; } for ($i = 0; $i < strlen($zh); $i++) { $s1 = substr($zh, $i, 1); $p = ord($s1); if ($p > 160) { $s2 = substr($zh, $i++, 2); $ret .= getfirstchar($s2); } else { $ret .= $s1; } } return $ret; } echo "这是中文字符串<br/>"; echo pinyin1('这是中文字符串');
2022年06月19日
315 阅读
0 评论
0 点赞
2022-06-19
【PHP】PHP根据身份证号获取星座
<?php // 根据身份证号,自动返回对应的星座 function get_xingzuo($cid) { $cid = getIDCard($cid); if (!isIdCard($cid)) return ''; $bir = substr($cid,10,4); $month = (int)substr($bir,0,2); $day = (int)substr($bir,2); $strValue = ''; if (($month == 1 && $day >= 20) || ($month == 2 && $day <= 18)) { $strValue = "水瓶座"; } else if (($month == 2 && $day >= 19) || ($month == 3 && $day <= 20)) { $strValue = "双鱼座"; } else if (($month == 3 && $day > 20) || ($month == 4 && $day <= 19)) { $strValue = "白羊座"; } else if (($month == 4 && $day >= 20) || ($month == 5 && $day <= 20)) { $strValue = "金牛座"; } else if (($month == 5 && $day >= 21) || ($month == 6 && $day <= 21)) { $strValue = "双子座"; } else if (($month == 6 && $day > 21) || ($month == 7 && $day <= 22)) { $strValue = "巨蟹座"; } else if (($month == 7 && $day > 22) || ($month == 8 && $day <= 22)) { $strValue = "狮子座"; } else if (($month == 8 && $day >= 23) || ($month == 9 && $day <= 22)) { $strValue = "处女座"; } else if (($month == 9 && $day >= 23) || ($month == 10 && $day <= 23)) { $strValue = "天秤座"; } else if (($month == 10 && $day > 23) || ($month == 11 && $day <= 22)) { $strValue = "天蝎座"; } else if (($month == 11 && $day > 22) || ($month == 12 && $day <= 21)) { $strValue = "射手座"; } else if (($month == 12 && $day > 21) || ($month == 1 && $day <= 19)) { $strValue = "魔羯座"; } return $strValue; } // 根据身份证号,自动返回对应的生肖 function get_shengxiao($cid) { $cid = getIDCard($cid); if (!isIdCard($cid)) return ''; $start = 1901; $end = $end = (int)substr($cid,6,4); $x = ($start - $end) % 12; $value = ""; if ($x == 1 || $x == -11) {$value = "鼠";} if ($x == 0) { $value = "牛";} if ($x == 11 || $x == -1) {$value = "虎";} if ($x == 10 || $x == -2) {$value = "兔";} if ($x == 9 || $x == -3) {$value = "龙";} if ($x == 8 || $x == -4) {$value = "蛇";} if ($x == 7 || $x == -5) {$value = "马";} if ($x == 6 || $x == -6) {$value = "羊";} if ($x == 5 || $x == -7) {$value = "猴";} if ($x == 4 || $x == -8) {$value = "鸡";} if ($x == 3 || $x == -9) {$value = "狗";} if ($x == 2 || $x == -10) {$value = "猪";} return $value; } function get_xingbie($cid,$comm=0) { //根据身份证号,自动返回性别 $cid = getIDCard($cid); if (!isIdCard($cid)) return ''; $sexint = (int)substr($cid,16,1); if($comm >0){ return $sexint % 2 === 0 ? '女士' : '先生'; }else{ return $sexint % 2 === 0 ? '女' : '男'; } } // 功能:把15位身份证转换成18位 function getIDCard($idCard) { // 若是15位,则转换成18位;否则直接返回ID if (15 == strlen ( $idCard )) { $W = array (7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1 ); $A = array ("1","0","X","9","8","7","6","5","4","3","2" ); $s = 0; $idCard18 = substr ( $idCard, 0, 6 ) . "19" . substr ( $idCard, 6 ); $idCard18_len = strlen ( $idCard18 ); for($i = 0; $i < $idCard18_len; $i ++) { $s = $s + substr ( $idCard18, $i, 1 ) * $W [$i]; } $idCard18 .= $A [$s % 11]; return $idCard18; } else { return $idCard; } } ?>
2022年06月19日
261 阅读
0 评论
0 点赞
2022-06-19
【PHP】数据校验规则
/** * @name: check_data * @description: 检测数据规则 * @param: string 被检测的原字符串 * @param: string 被检测的类型 * @return: boolean * @create: 2014-10-10 **/ function check_data($string, $type='email'){ $return = FALSE; switch($type){ case 'email' : {$return = preg_match("/^(\w+[-+.]*\w+)*@(\w+([-.]*\w+)*\.\w+([-.]*\w+)*)$/", $string); break;} case 'http' : {$return = preg_match("/^http:\/\/[A-Za-z0-9-]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"])*$/", $string); break;} case 'qq' : {$return = preg_match("/^[1-9]\d{4,11}$/", $string); break;} case 'post' : {$return = preg_match("/^[1-9]\d{5}$/", $string); break;} case 'idnum' : {$return = preg_match("/^\d{15}(\d{2}[A-Za-z0-9])?$/", $string); break;} case 'china' : {$return = preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/", $string); break;} //GBK中文 case 'english' : {$return = preg_match("/^[A-Za-z]+$/", $string); break;} case 'mobile' : {$return = preg_match("/^((\(\d{3}\))|(\d{3}\-))?((13)|(14)|(15)|(17)|(18)){1}\d{9}$/", $string); break;} case 'phone' : {$return = preg_match("/^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/", $string); break;} case 'safe' : {$return = preg_match("/^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/", $string) != 0 ? TRUE : FALSE; break;} case 'age' : {$return = (preg_match("/^(-{0,1}|\+{0,1})[0-9]+(\.{0,1}[0-9]+)$/", $string) && intval($string) <= 130 && intval($string) >= 12) ? TRUE : FALSE; break;} case 'eng_num' : {$return = preg_match("/^[A-Za-z0-9]+$/", $string); break;} case 'password' : {$return = (preg_match("/^[A-Za-z0-9]+$/", $string) && strlen($string) <= 32 && strlen($string) >= 6) ? TRUE : FALSE; break;} case 'datetime' : {$return = preg_match('/^[\d]{4}-[\d]{1,2}-[\d]{1,2}\s[\d]{1,2}:[\d]{1,2}:[\d]{1,2}$/', $string); break;} case 'datetimes' : {$return = preg_match('/^[\d]{4}-[\d]{2}-[\d]{2}\s[\d]{2}:[\d]{2}:[\d]{2}$/', $string); break;} case 'date' : {$return = preg_match('/^[\d]{4}-[\d]{1,2}-[\d]{1,2}$/', $string); break;} case 'dates' : {$return = preg_match('/^[\d]{4}-[\d]{2}-[\d]{2}$/', $string); break;} case 'time' : {$return = preg_match('/^[\d]{1,2}:[\d]{1,2}:[\d]{1,2}$/', $string); break;} case 'times' : {$return = preg_match('/^[\d]{2}:[\d]{2}:[\d]{2}$/', $string); break;} case 'ip' : {$return = preg_match("/^\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b$/", $string); break;} case 'incchinese' : {$return = preg_match('/[\x{4e00}-\x{9fa5}]+/u', $string); break;} //是否包含中文 case 'plusnum' : {$return = preg_match('/^[1-9]*[1-9][0-9]*$/', $string); break;} //是否是正整数 case 'hostrecord' : {$return = preg_match('/^[A-Z_a-z0-9][A-Za-z0-9-]+(\.[A-Za-z0-9-_]+)*$/', $string); break;} //正确的主机记录,english case 'cnhostrecord' : {$return = preg_match('/^[_a-zA-Z0-9]*([\x{4e00}-\x{9fa5}]*[-a-zA-Z0-9\.]*)+[a-zA-Z0-9_]$/iu', $string); break;} //正确的主机记录,english chinese case 'domain' : {$return = preg_match('/^[A-Za-z0-9][A-Za-z0-9-]+(\.[A-Za-z0-9-]+){1,3}$/', $string); break;} //是否是域名 case 'cndomain' : {$return = (preg_match('/[\x{4e00}-\x{9fa5}]+/u', $string) && preg_match('/^([-a-zA-Z0-9\.]*[\x{4e00}-\x{9fa5}]*[-a-zA-Z0-9\.]*)+\.(中国|公司|网络|CN|COM|NET)$/iu', $string)) ? TRUE : FALSE; break;} //是否中文域名 case 'mac' : {$return = preg_match('/^[a-fA-F\d]{2}:[a-fA-F\d]{2}:[a-fA-F\d]{2}:[a-fA-F\d]{2}:[a-fA-F\d]{2}:[a-fA-F\d]{2}$/', $string); break;} case 'ipv6' : {$return = preg_match('/^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/', $string); break;} } gettype($return) == 'integer' && $return = $return == 0 ? FALSE : TRUE; return $return; }
2022年06月19日
287 阅读
0 评论
0 点赞
2022-06-19
【PHP】PHP获取手机相关信息
<?php /* *该PHP操作类实现获取手机号 手机头信息,取UA,取得手机类型,判断是否是opera,判断是否是m3gate,取得HA,取得手机IP */ /** * @desc 手机操作类 获取手机相关信息 * @since */ class mobile { /** * 函数名称: getPhoneNumber * 函数功能: 取手机号 * 输入参数: none * 函数返回值: 成功返回号码,失败返回false * 其它说明: 说明 */ public function getPhoneNumber() { if (isset($_SERVER['HTTP_X_NETWORK_INFO'])) { $str1 = $_SERVER['HTTP_X_NETWORK_INFO']; $getstr1 = preg_replace('/(.*,)(11[d])(,.*)/i',"",$str1); Return $getstr1; }elseif (isset($_SERVER['HTTP_X_UP_CALLING_LINE_ID'])) { $getstr2 = $_SERVER['HTTP_X_UP_CALLING_LINE_ID']; Return $getstr2; }elseif (isset($_SERVER['HTTP_X_UP_SUBNO'])) { $str3 = $_SERVER['HTTP_X_UP_SUBNO']; $getstr3 = preg_replace('/(.*)(11[d])(.*)/i',"",$str3); Return $getstr3; }elseif (isset($_SERVER['DEVICEID'])) { Return $_SERVER['DEVICEID']; }else { Return false; } } /** * 函数名称: getHttpHeader * 函数功能: 取头信息 * 输入参数: none * 函数返回值: 成功返回号码,失败返回false * 其它说明: 说明 */ public function getHttpHeader() { $str = ""; foreach ($_SERVER as $key=>$val) { $gstr = str_replace("&","&",$val); $str.= "$key -> ".$gstr."rn"; } Return $str; } /** * 函数名称: getUA * 函数功能: 取UA * 输入参数: none * 函数返回值: 成功返回号码,失败返回false * 其它说明: 说明 */ public function getUA() { if (isset($_SERVER['HTTP_USER_AGENT'])) { Return $_SERVER['HTTP_USER_AGENT']; }else { Return false; } } /** * 函数名称: getPhoneType * 函数功能: 取得手机类型 * 输入参数: none * 函数返回值: 成功返回string,失败返回false * 其它说明: 说明 */ public function getPhoneType() { $ua = $this->getUA(); if($ua!=false) { $str = explode(" ",$ua); Return $str[0]; }else { Return false; } } /** * 函数名称: isOpera * 函数功能: 判断是否是opera * 输入参数: none www.knowsky.com * 函数返回值: 成功返回string,失败返回false * 其它说明: 说明 */ public function isOpera() { $uainfo = $this->getUA(); if (preg_match('/.*Opera.*/i',$uainfo)) { Return true; }else { Return false; } } /** * 函数名称: isM3gate * 函数功能: 判断是否是m3gate * 输入参数: none * 函数返回值: 成功返回string,失败返回false * 其它说明: 说明 */ public function isM3gate() { $uainfo = $this->getUA(); if (preg_match('/M3Gate/i',$uainfo)) { Return true; }else { Return false; } } /** * 函数名称: getHttpAccept * 函数功能: 取得HA * 输入参数: none * 函数返回值: 成功返回string,失败返回false * 其它说明: 说明 */ public function getHttpAccept() { if (isset($_SERVER['HTTP_ACCEPT'])) { Return $_SERVER['HTTP_ACCEPT']; }else { Return false; } } /** * 函数名称: getIP * 函数功能: 取得手机IP * 输入参数: none * 函数返回值: 成功返回string * 其它说明: 说明 */ public function getIP() { $ip=getenv('REMOTE_ADDR'); $ip_ = getenv('HTTP_X_FORWARDED_FOR'); if (($ip_ != "") && ($ip_ != "unknown")) { $ip=$ip_; } return $ip; } } ?>亲测手机号获取不到 ;可以考虑别的方法了,这里仅供参考
2022年06月19日
250 阅读
0 评论
0 点赞
2022-06-19
【PHP】PHP检测浏览器语言
如果你的网站上有多种语言,那么可以使用这段代码 作为默认的语言来检测浏览器语言。该段代码将返回 浏览器客户端使用的初始语言。 function get_client_language($availableLanguages, $default='en'){ if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $langs=explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']); foreach ($langs as $value){ $choice=substr($value,0,2); if(in_array($choice, $availableLanguages)){ return $choice; } } } return $default; }
2022年06月19日
227 阅读
0 评论
0 点赞
2022-06-19
【PHP】PHP实现字符串截取,支持中文和其他编码
<?php /** * 字符串截取,支持中文和其他编码 * @param [string] $str [字符串] * @param integer $start [起始位置] * @param integer $length [截取长度] * @param string $charset [字符串编码] * @param boolean $suffix [是否有省略号] * @return [type] [description] */ function msubstr($str, $start=0, $length=15, $charset="utf-8", $suffix=true) { if(function_exists("mb_substr")) { return mb_substr($str, $start, $length, $charset); } elseif(function_exists('iconv_substr')) { return iconv_substr($str,$start,$length,$charset); } $re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/"; $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/"; $re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/"; $re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/"; preg_match_all($re[$charset], $str, $match); $slice = join("",array_slice($match[0], $start, $length)); if($suffix) { return $slice."…"; } return $slice; } /* 这里的关键,$charset="utf-8",对中文支持是很重要的!不然出现一些?号,就要挨批了! 使用方法如下: echo msubstr($str, $start=0, $length=15, $charset="utf-8", $suffix=true) /*
2022年06月19日
267 阅读
0 评论
0 点赞
2022-06-19
【PHP】PHP实现中文转拼音
<?php /** * PHP 汉字转拼音 * @author Jerryli(hzjerry@gmail.com) * @version V0.20140715 * @package SPFW.core.lib.final * @global SEA_PHP_FW_VAR_ENV * @example * echo CUtf8_PY::encode('阿里巴巴科技有限公司'); //编码为拼音首字母 * echo CUtf8_PY::encode('阿里巴巴科技有限公司', 'all'); //编码为全拼音 */ class CUtf8_PY { /** * 拼音字符转换图 * @var array */ private static $_aMaps = array( 'a'=>-20319,'ai'=>-20317,'an'=>-20304,'ang'=>-20295,'ao'=>-20292, 'ba'=>-20283,'bai'=>-20265,'ban'=>-20257,'bang'=>-20242,'bao'=>-20230,'bei'=>-20051,'ben'=>-20036,'beng'=>-20032,'bi'=>-20026,'bian'=>-20002,'biao'=>-19990,'bie'=>-19986,'bin'=>-19982,'bing'=>-19976,'bo'=>-19805,'bu'=>-19784, 'ca'=>-19775,'cai'=>-19774,'can'=>-19763,'cang'=>-19756,'cao'=>-19751,'ce'=>-19746,'ceng'=>-19741,'cha'=>-19739,'chai'=>-19728,'chan'=>-19725,'chang'=>-19715,'chao'=>-19540,'che'=>-19531,'chen'=>-19525,'cheng'=>-19515,'chi'=>-19500,'chong'=>-19484,'chou'=>-19479,'chu'=>-19467,'chuai'=>-19289,'chuan'=>-19288,'chuang'=>-19281,'chui'=>-19275,'chun'=>-19270,'chuo'=>-19263,'ci'=>-19261,'cong'=>-19249,'cou'=>-19243,'cu'=>-19242,'cuan'=>-19238,'cui'=>-19235,'cun'=>-19227,'cuo'=>-19224, 'da'=>-19218,'dai'=>-19212,'dan'=>-19038,'dang'=>-19023,'dao'=>-19018,'de'=>-19006,'deng'=>-19003,'di'=>-18996,'dian'=>-18977,'diao'=>-18961,'die'=>-18952,'ding'=>-18783,'diu'=>-18774,'dong'=>-18773,'dou'=>-18763,'du'=>-18756,'duan'=>-18741,'dui'=>-18735,'dun'=>-18731,'duo'=>-18722, 'e'=>-18710,'en'=>-18697,'er'=>-18696, 'fa'=>-18526,'fan'=>-18518,'fang'=>-18501,'fei'=>-18490,'fen'=>-18478,'feng'=>-18463,'fo'=>-18448,'fou'=>-18447,'fu'=>-18446, 'ga'=>-18239,'gai'=>-18237,'gan'=>-18231,'gang'=>-18220,'gao'=>-18211,'ge'=>-18201,'gei'=>-18184,'gen'=>-18183,'geng'=>-18181,'gong'=>-18012,'gou'=>-17997,'gu'=>-17988,'gua'=>-17970,'guai'=>-17964,'guan'=>-17961,'guang'=>-17950,'gui'=>-17947,'gun'=>-17931,'guo'=>-17928, 'ha'=>-17922,'hai'=>-17759,'han'=>-17752,'hang'=>-17733,'hao'=>-17730,'he'=>-17721,'hei'=>-17703,'hen'=>-17701,'heng'=>-17697,'hong'=>-17692,'hou'=>-17683,'hu'=>-17676,'hua'=>-17496,'huai'=>-17487,'huan'=>-17482,'huang'=>-17468,'hui'=>-17454,'hun'=>-17433,'huo'=>-17427, 'ji'=>-17417,'jia'=>-17202,'jian'=>-17185,'jiang'=>-16983,'jiao'=>-16970,'jie'=>-16942,'jin'=>-16915,'jing'=>-16733,'jiong'=>-16708,'jiu'=>-16706,'ju'=>-16689,'juan'=>-16664,'jue'=>-16657,'jun'=>-16647, 'ka'=>-16474,'kai'=>-16470,'kan'=>-16465,'kang'=>-16459,'kao'=>-16452,'ke'=>-16448,'ken'=>-16433,'keng'=>-16429,'kong'=>-16427,'kou'=>-16423,'ku'=>-16419,'kua'=>-16412,'kuai'=>-16407,'kuan'=>-16403,'kuang'=>-16401,'kui'=>-16393,'kun'=>-16220,'kuo'=>-16216, 'la'=>-16212,'lai'=>-16205,'lan'=>-16202,'lang'=>-16187,'lao'=>-16180,'le'=>-16171,'lei'=>-16169,'leng'=>-16158,'li'=>-16155,'lia'=>-15959,'lian'=>-15958,'liang'=>-15944,'liao'=>-15933,'lie'=>-15920,'lin'=>-15915,'ling'=>-15903,'liu'=>-15889,'long'=>-15878,'lou'=>-15707,'lu'=>-15701,'lv'=>-15681,'luan'=>-15667,'lue'=>-15661,'lun'=>-15659,'luo'=>-15652, 'ma'=>-15640,'mai'=>-15631,'man'=>-15625,'mang'=>-15454,'mao'=>-15448,'me'=>-15436,'mei'=>-15435,'men'=>-15419,'meng'=>-15416,'mi'=>-15408,'mian'=>-15394,'miao'=>-15385,'mie'=>-15377,'min'=>-15375,'ming'=>-15369,'miu'=>-15363,'mo'=>-15362,'mou'=>-15183,'mu'=>-15180, 'na'=>-15165,'nai'=>-15158,'nan'=>-15153,'nang'=>-15150,'nao'=>-15149,'ne'=>-15144,'nei'=>-15143,'nen'=>-15141,'neng'=>-15140,'ni'=>-15139,'nian'=>-15128,'niang'=>-15121,'niao'=>-15119,'nie'=>-15117,'nin'=>-15110,'ning'=>-15109,'niu'=>-14941,'nong'=>-14937,'nu'=>-14933,'nv'=>-14930,'nuan'=>-14929,'nue'=>-14928,'nuo'=>-14926, 'o'=>-14922,'ou'=>-14921, 'pa'=>-14914,'pai'=>-14908,'pan'=>-14902,'pang'=>-14894,'pao'=>-14889,'pei'=>-14882,'pen'=>-14873,'peng'=>-14871,'pi'=>-14857,'pian'=>-14678,'piao'=>-14674,'pie'=>-14670,'pin'=>-14668,'ping'=>-14663,'po'=>-14654,'pu'=>-14645, 'qi'=>-14630,'qia'=>-14594,'qian'=>-14429,'qiang'=>-14407,'qiao'=>-14399,'qie'=>-14384,'qin'=>-14379,'qing'=>-14368,'qiong'=>-14355,'qiu'=>-14353,'qu'=>-14345,'quan'=>-14170,'que'=>-14159,'qun'=>-14151, 'ran'=>-14149,'rang'=>-14145,'rao'=>-14140,'re'=>-14137,'ren'=>-14135,'reng'=>-14125,'ri'=>-14123,'rong'=>-14122,'rou'=>-14112,'ru'=>-14109,'ruan'=>-14099,'rui'=>-14097,'run'=>-14094,'ruo'=>-14092, 'sa'=>-14090,'sai'=>-14087,'san'=>-14083,'sang'=>-13917,'sao'=>-13914,'se'=>-13910,'sen'=>-13907,'seng'=>-13906,'sha'=>-13905,'shai'=>-13896,'shan'=>-13894,'shang'=>-13878,'shao'=>-13870,'she'=>-13859,'shen'=>-13847,'sheng'=>-13831,'shi'=>-13658,'shou'=>-13611,'shu'=>-13601,'shua'=>-13406,'shuai'=>-13404,'shuan'=>-13400,'shuang'=>-13398,'shui'=>-13395,'shun'=>-13391,'shuo'=>-13387,'si'=>-13383,'song'=>-13367,'sou'=>-13359,'su'=>-13356,'suan'=>-13343,'sui'=>-13340,'sun'=>-13329,'suo'=>-13326, 'ta'=>-13318,'tai'=>-13147,'tan'=>-13138,'tang'=>-13120,'tao'=>-13107,'te'=>-13096,'teng'=>-13095,'ti'=>-13091,'tian'=>-13076,'tiao'=>-13068,'tie'=>-13063,'ting'=>-13060,'tong'=>-12888,'tou'=>-12875,'tu'=>-12871,'tuan'=>-12860,'tui'=>-12858,'tun'=>-12852,'tuo'=>-12849, 'wa'=>-12838,'wai'=>-12831,'wan'=>-12829,'wang'=>-12812,'wei'=>-12802,'wen'=>-12607,'weng'=>-12597,'wo'=>-12594,'wu'=>-12585, 'xi'=>-12556,'xia'=>-12359,'xian'=>-12346,'xiang'=>-12320,'xiao'=>-12300,'xie'=>-12120,'xin'=>-12099,'xing'=>-12089,'xiong'=>-12074,'xiu'=>-12067,'xu'=>-12058,'xuan'=>-12039,'xue'=>-11867,'xun'=>-11861, 'ya'=>-11847,'yan'=>-11831,'yang'=>-11798,'yao'=>-11781,'ye'=>-11604,'yi'=>-11589,'yin'=>-11536,'ying'=>-11358,'yo'=>-11340,'yong'=>-11339,'you'=>-11324,'yu'=>-11303,'yuan'=>-11097,'yue'=>-11077,'yun'=>-11067, 'za'=>-11055,'zai'=>-11052,'zan'=>-11045,'zang'=>-11041,'zao'=>-11038,'ze'=>-11024,'zei'=>-11020,'zen'=>-11019,'zeng'=>-11018,'zha'=>-11014,'zhai'=>-10838,'zhan'=>-10832,'zhang'=>-10815,'zhao'=>-10800,'zhe'=>-10790,'zhen'=>-10780,'zheng'=>-10764,'zhi'=>-10587,'zhong'=>-10544,'zhou'=>-10533,'zhu'=>-10519,'zhua'=>-10331,'zhuai'=>-10329,'zhuan'=>-10328,'zhuang'=>-10322,'zhui'=>-10315,'zhun'=>-10309,'zhuo'=>-10307,'zi'=>-10296,'zong'=>-10281,'zou'=>-10274,'zu'=>-10270,'zuan'=>-10262,'zui'=>-10260,'zun'=>-10256,'zuo'=>-10254 ); /** * 将中文编码成拼音 * @param string $utf8Data utf8字符集数据 * @param string $sRetFormat 返回格式 [head:首字母|all:全拼音] * @return string */ public static function encode($utf8Data, $sRetFormat='head'){ $sGBK = iconv('UTF-8', 'GBK', $utf8Data); $aBuf = array(); for ($i=0, $iLoop=strlen($sGBK); $i<$iLoop; $i++) { $iChr = ord($sGBK{$i}); if ($iChr>160) $iChr = ($iChr<<8) + ord($sGBK{++$i}) - 65536; if ('head' === $sRetFormat) $aBuf[] = substr(self::zh2py($iChr),0,1); else $aBuf[] = self::zh2py($iChr); } if ('head' === $sRetFormat) return implode('', $aBuf); else return implode(' ', $aBuf); } /** * 中文转换到拼音(每次处理一个字符) * @param number $iWORD 待处理字符双字节 * @return string 拼音 */ private static function zh2py($iWORD) { if($iWORD>0 && $iWORD<160 ) { return chr($iWORD); } elseif ($iWORD<-20319||$iWORD>-10247) { return ''; } else { foreach (self::$_aMaps as $py => $code) { if($code > $iWORD) break; $result = $py; } return $result; } } } ?>
2022年06月19日
252 阅读
0 评论
0 点赞
2022-06-19
【PHP】PHP身份证验证类
<?php /** *身份证号处理函数 */ /** * 功能:根据身份证号,自动返回生日 * @param stirng $IDCard 身份证号 * @return Ambigous <string, NULL> */ function getBrithday ($idCard) { if (strlen($idCard) == 18) { $birthday = substr($idCard, 6, 4) . '-' . substr($idCard, 10, 2) . '-' . substr($idCard, 12, 2); } elseif (strlen($idCard) == 15) { $birthday = "19" . substr($idCard, 6, 2) . '-' . substr($idCard, 8, 2) . '-' . substr($idCard, 10, 2); } else { $birthday = null; } return $birthday; } /** * 功能:根据身份证号,自动返回性别 * @param string $cid 身份证号 * @param number $comm 返回的性别类型 * @return string 男/女 1/0 */ function getSex ($cid, $comm = 0) { $cid = getIDCard($cid); $sexint = (int) substr($cid, 16, 1); if ($comm > 0) { return $sexint % 2 === 0 ? '女' : '男'; } else { return $sexint % 2 === 0 ? '0' : '1'; } } /** * 功能:把15位身份证转换成18位 * @param string $idCard * @return newid or id */ function getIDCard ($idCard) { // 若是15位,则转换成18位;否则直接返回ID if (15 == strlen($idCard)) { $w = array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1); $a = array("1","0","X","9","8","7","6","5","4","3","2"); $s = 0; $idCard18 = substr($idCard, 0, 6) . "19" . substr($idCard, 6); $idCard18_len = strlen($idCard18); for ($i = 0; $i < $idCard18_len; $i ++) { $s = $s + substr($idCard18, $i, 1) * $w[$i]; } return $idCard18.$a[$s % 11]; } else { return $idCard; } } /** * 根据身份证号返回年龄 * @param string $id 身份证号 * @return string|number */ function getAge($id){ //过了这年的生日才算多了1周岁 if(empty($id)) return ''; $date=strtotime(substr($id,6,8)); //获得出生年月日的时间戳 $today=strtotime('today'); //获得今日的时间戳 $diff=floor(($today-$date)/86400/365); //得到两个日期相差的大体年数 //strtotime加上这个年数后得到那日的时间戳后与今日的时间戳相比 $age=strtotime(substr($id,6,8).' +'.$diff.'years')>$today?($diff+1):$diff; return $age; }
2022年06月19日
333 阅读
0 评论
0 点赞
2022-06-19
【PHP】PHP提取网页的关键词
$meta = get_meta_tags('http://www.emoticode.net/'); $keywords = $meta['keywords']; // Split keywords $keywords = explode(',', $keywords ); // Trim them $keywords = array_map( 'trim', $keywords ); // Remove empty values $keywords = array_filter( $keywords ); print_r( $keywords );更多爬取方法可参考:QueryList
2022年06月19日
281 阅读
0 评论
0 点赞
2022-06-19
【PHP】PHP生成唯一ID
<?php header("Content-Type: text/html; charset=UTF-8"); date_default_timezone_set("PRC"); // error_reporting(0); // 生成ID:Unix时间戳+毫秒+微妙+四位随机数字(20位数字,2028/06/15 前可存入MySQL,数据类型:BIGINT) $id = microtime(); $id = substr($id, 11) . substr($id, 2, 6) . mt_rand(1000, 9999); //循环里面可用 public function setUUID(){ $currentTimestamp = microtime(true); $uuid = self::generateUUIDInner(); while (in_array($uuid, self::$generatedUUIDs)) { $uuid = self::generateUUIDInner(); } self::$generatedUUIDs[] = $uuid; self::$lastTimestamp = $currentTimestamp; return $uuid; } private static function generateUUIDInner() { $milliseconds = floor(microtime(true) * 1000); $randomPart = mt_rand(100, 999); $uuid = date('YmdHis').substr(strval($milliseconds), -3).$randomPart; return $uuid; echo "Generated UUID inside: ".$uuid."\n"; die; }
2022年06月19日
288 阅读
0 评论
0 点赞
2022-06-19
【PHP】ThinkPHP5.1开发技巧
用facade替换类实例化操作,代码简洁、清淅易于维护app()统一操作,代码清淅简洁数据处理统一定义于model中,比如数据缓存,数据转换,拼接日志可利用注入、行为、控制器前后置操作来执行记录方法定义DS简化代码 define('DS', DIRECTORY\_SEPARATOR)善用定义命令行console减少重复工作前端组件集成,可参照fastadmin,dolphinPHP中的集成方法,可提高开发效率,使用方法,可通过 thinkphp\helper.php 自带助手函数,学习内置类调用方法善用traits减少重复代码控制器: 前置操作,方便临时增加的处理过程; 当然中间插件也是不错的选择模型:数据转换,缓存.....与数据相关的,统一放于模型之中加载与配置 use think\facace\Load; use think\facace\Config include app('env')\->get('app\_path').'chsys'.DIRECTORY\_SEPARATOR.'common.php';只在部分控制器添加特定配置 ..... class Index extends Admin{ //初始化 左菜单 public function _initialize(){ parent::_initialize(); \think\facade\Config::set('my',....); } initialize控制器 Route,Controller\think\facace\Route; \think\Controller;只在部分控制器中,加启用配置或者添加路由方法可通过行为【tags.php】添加 或者 intiallize()中动态加载 class Linktest extends Admin{ //初始化 左菜单 public function _initialize(){ parent::_initialize(); Route:: // dump((new CustomerM)->quickAdd()); } 数据处理 Db,Model \think\Db; \think\Model; hasOne('关联模型名','外键名','主键名',['模型别名定义'],'join类型');实用数据查询方法默认模型返回为数据集格式数据 转换为数组方法 用函数( collection() ) collection(CustomerM::group('name')->field('id,name')->select())->toArray();单条记录返回数据方法 CustomerM::find(1)->toArray(); CustomerM::find(1)->toArray();获取指定字段所有数据方法 CustomerM::where('name','like','%name%')->column('id,name'); //返回格式为 [ '$id'=>"$name", '$id'=>"$name" ];返回指定字段的值 【单条记录】 CustomerM::where('id',5)->value('name'); //或者 CustomerM::where('id',5)->getFieldName();验证内置支持验证规则// 验证规则默认提示信息 protected static $typeMsg = [ 'require' => ':attribute不能为空', 'number' => ':attribute必须是数字', 'integer' => ':attribute必须是整数', 'float' => ':attribute必须是浮点数', 'boolean' => ':attribute必须是布尔值', 'email' => ':attribute格式不符', 'array' => ':attribute必须是数组', 'accepted' => ':attribute必须是yes、on或者1', 'date' => ':attribute格式不符合', 'file' => ':attribute不是有效的上传文件', 'image' => ':attribute不是有效的图像文件', 'alpha' => ':attribute只能是字母', 'alphaNum' => ':attribute只能是字母和数字', 'alphaDash' => ':attribute只能是字母、数字和下划线_及破折号-', 'activeUrl' => ':attribute不是有效的域名或者IP', 'chs' => ':attribute只能是汉字', 'chsAlpha' => ':attribute只能是汉字、字母', 'chsAlphaNum' => ':attribute只能是汉字、字母和数字', 'chsDash' => ':attribute只能是汉字、字母、数字和下划线_及破折号-', 'url' => ':attribute不是有效的URL地址', 'ip' => ':attribute不是有效的IP地址', 'dateFormat' => ':attribute必须使用日期格式 :rule', 'in' => ':attribute必须在 :rule 范围内', 'notIn' => ':attribute不能在 :rule 范围内', 'between' => ':attribute只能在 :1 - :2 之间', 'notBetween' => ':attribute不能在 :1 - :2 之间', 'length' => ':attribute长度不符合要求 :rule', 'max' => ':attribute长度不能超过 :rule', 'min' => ':attribute长度不能小于 :rule', 'after' => ':attribute日期不能小于 :rule', 'before' => ':attribute日期不能超过 :rule', 'expire' => '不在有效期内 :rule', 'allowIp' => '不允许的IP访问', 'denyIp' => '禁止的IP访问', 'confirm' => ':attribute和确认字段:2不一致', 'different' => ':attribute和比较字段:2不能相同', 'egt' => ':attribute必须大于等于 :rule', 'gt' => ':attribute必须大于 :rule', 'elt' => ':attribute必须小于等于 :rule', 'lt' => ':attribute必须小于 :rule', 'eq' => ':attribute必须等于 :rule', 'unique' => ':attribute已存在', 'regex' => ':attribute不符合指定规则', 'method' => '无效的请求类型', 'token' => '令牌数据无效', 'fileSize' => '上传文件大小不符', 'fileExt' => '上传文件后缀不符', 'fileMime' => '上传文件类型不符', ];
2022年06月19日
411 阅读
0 评论
0 点赞
1
...
5
6
7
8