2022-07-21 PHP面向对象的链式调用方式 PHP面向对象的链式调用方式 实现起来也还蛮简单的,只需要在每个方法最后返回$this就可以了<?php class wc { public function __construct($who) { echo "{$who}准备去上厕所了"; } public function go() { echo "1.跑出了教室"; return $this; } public function action($ss) { echo $ss . "2.到了厕所,开始尿尿"; return $this; } public function back() { echo "3.尿尿结束,回到教室"; return $this; } } $xm = new wc("小明"); $xm->go()->... 2022年07月21日 81 阅读 0 评论
2022-07-15 微信小程序长按事件 微信小程序长按事件 <view bindtouchstart="touchstart" bindtouchend="touchend">123456</view> //touch start touchstart: function(e) { this.startTime = e.timeStamp; console.log(this.startTime) }, //touch end touchend: function(e) { this.endTime = e.timeStamp; console.log(this.endTime) console.log("endTime - startTime = " + (this.endTime-this.startTime)); if (this.endTime - this.startTime>600){ console.log('长按') ... 2022年07月15日 85 阅读 0 评论
2022-06-16 ThinkPHP 过滤重复数据distinct和group ThinkPHP 过滤重复数据distinct和group //distinct方法去重 $data = (new classifyModel())->distinct(true)->field('name')->select()->toArray(); //group方法去重 $data = (new classifyModel())->group('name')->select()->toArray(); 对于两种去重方式: distinct去重、简单易用,但只能对于单一字段去重,并且最终的结果也仅为去重的字段,实际应用价值不是特别大。 group去重,最终的显示结果为所有字段,且对单一字段进行了去重操作,效果不错。 2022年06月16日 164 阅读 0 评论
2022-06-10 PHP面向对象封装MySQL PDO(已使用预处理) PHP面向对象封装MySQL PDO(已使用预处理) Mysql.class.php<?php class Mysql { public $link; public function __construct() { $this->conn(); } /** * 连接数据库,从配置文件读取配置信息 */ public function conn() { $cfg = require 'config.php'; try { $this->link = new PDO("mysql:dbname={$cfg['databaseName']};host={$cfg['host']};charset={$cfg['charset']};port={$cfg['port']}", $cfg['name'], $cfg['password']); $this->link->setAttribute(PDO::ATTR_EMU... 2022年06月10日 180 阅读 0 评论
2022-06-06 js执行提示Uncaught URIError: URI malformed js执行提示Uncaught URIError: URI malformed 由于decodeURI转码时,通过%进行解析,如果字符串中存在%则会出现URI malformed解决方法将字符串中的%替换为25%就行了var str = '1%2'; if(str.indexOf('%') > -1) { str = str.replace(/%/g,'%25'); } 2022年06月06日 171 阅读 0 评论
2022-05-21 JQuery长按事件 JQuery长按事件 $(".text").on({ touchstart: function(e) { var oSpan = e.currentTarget.lastElementChild // 长按事件触发 timeOutEvent = setTimeout(function() { timeOutEvent = 0; console.log('你长按了'); }, 500); }, touchmove: function() { clearTimeout(timeOutEvent); timeOutEvent = 0; }, touchend: function() { clearTimeout(timeOutEvent); if (timeOutEvent != 0) { console.log('你点击了'); ... 2022年05月21日 241 阅读 0 评论
2022-05-13 Linux grep命令基本语法 Linux grep命令基本语法 1、在当前目录中,查找后缀有 file 字样的文件中包含 test 字符串的文件,并打印出该字符串的行:grep test *file2、以递归的方式查找符合条件的文件:grep -r test *3、反向查找:grep -v test *4、忽略大小写查找:grep -i test *6、显示查询结果行号:grep -n test *7、显示总共有多少行符合条件:grep -c test *8、匹配符合条件上下文N行:grep -C N test *9、只匹配单词:grep -w test *10、查找并列出匹配的文件名:grep -l test *11、查找并列出不匹配的文件名:grep -L test *12、过滤带注释行或空行:grep -v '^#' * | grep -v '^$' * 2022年05月13日 323 阅读 0 评论
2022-04-04 js实现html导出为PDF文件 js实现html导出为PDF文件 html2canvas官网:http://html2canvas.hertzen.com/<?php if(!empty($_POST['datauri'])){ if(preg_match('/data:.*?;base64,/i',$_POST['datauri'])){ $datauri = base64_decode(preg_replace('/data:.*?;base64,/i','',$_POST['datauri'])); $dir = 'upload/'; if(!is_dir($dir)){ mkdir($dir); } $file = md5($_SERVER['HTTP_USER_AGENT'] . $_SERVER['REMOTE_ADDR']).'.pdf'; try { file_put_contents($dir.$file,$datauri); $data = ['... 2022年04月04日 623 阅读 0 评论
2022-03-26 PHP将文件打包成zip PHP将文件打包成zip 单文件压缩<?php $zip = new ZipArchive(); $zip_filename = "img/".time().".zip"; // 指定一个压缩包地址 $zip->open($zip_filename, ZIPARCHIVE::CREATE); // 打开压缩包,没有则创建 // 参数1是要压缩的文件,参数2为压缩后,在压缩包中的文件名「这里我们把 1.jpg 文件压缩,压缩后的文件为 2.jpg」,如果需要的压缩后的文件跟原文件名一样 addFile() 的第二个参数可以改为 basename("img/2.jpg"),也就是原文件所在的路径 $zip->addFile("img/1.jpg",basename("2.jpg")); $res = $zip->close() 多文件压缩<?php $fileList = array( "img/1.jpg", "img/2.jpg&... 2022年03月26日 670 阅读 0 评论
2022-03-25 PHP实现图片压缩 PHP实现图片压缩 <?php echo get_thumb('img/1.jpg'); /** * 图片压缩处理 * @param string $sFile 源图片路径 * @param int $iWidth 自定义图片宽度 * @param int $iHeight 自定义图片高度 * @param bool $format 文件格式是否为 源文件_宽度_高度.后缀 * @return string 压缩后的图片路径 */ function get_thumb($sFile, $iWidth = '', $iHeight = '', $format = false) { $suffix = ['jpg', 'png', 'jpeg', 'webp']; //判断该图片是否存在 if (!file_exists($sFile)) return $sFile; //判断图片格式(图片文件后缀) $extend = explode(".", $sFile); $attach_fileext = strtolower(... 2022年03月25日 723 阅读 0 评论