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-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-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 评论
2022-03-02 微信小程序接入微信支付 微信小程序接入微信支付 获取openid参考微信授权登录微信小程序MD5加密(支持中文):https://zhizun.lanzouy.com/inF7G00vonmbpay.jsimport util from '../../utils/util.js' const md5 = require('../../utils/md5.js'); Page({ /** * 页面的初始数据 */ data: { id: '' }, /** * 生命周期函数--监听页面加载 */ onLoad: function () { }, submit(){ this.setData({id: 1}) this.unitedPayRequest('openid') }, /*统一支付接口*/ unitedPayRequest: function(openid){ var that = this; //统一支付签名 var accountInfo = wx.getAccountInfoSync(); ... 2022年03月02日 683 阅读 0 评论
2022-03-02 PHP xml和数组互转 PHP xml和数组互转 // xml转数组 function xml_array($xml){ //禁止引用外部xml实体 libxml_disable_entity_loader(true); $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); $val = json_decode(json_encode($xmlstring),true); return $val; } // 数组转xml function array_xml($arr){ $xml = "<xml>"; foreach ($arr as $key=>$val){ if(is_array($val)){ $xml.="<".$key.">".array_xml($val)."</".$k... 2022年03月02日 585 阅读 0 评论
2022-02-01 至尊API接口PHP源码 至尊API接口PHP源码 PHP:5.6以上二级目录:支持配置文件:common.php下载地址:https://zhizun.lanzouy.com/ioyo6zhjd8h 2022年02月01日 558 阅读 0 评论
2021-12-28 Laravel apache和nginx伪静态 Laravel apache和nginx伪静态 nginxlocation / { try_files $uri $uri/ /index.php?$query_string; } apache<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^\index\/show$ laravel/public/show [R=301] # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_F... 2021年12月28日 672 阅读 0 评论
2021-12-25 关于¬ify_url变成¬ify_url的解决方法 关于¬ify_url变成¬ify_url的解决方法 在页面上显示¬ify_url不管怎样都变成¬ify_url,后来发现把&改为&就可以了PHP字符替换$str = '¬ify_url'; $url = str_replace("&","&",$str); js字符替换str = '¬ify_url'; url = str.replace(/&/, "&"); 2021年12月25日 574 阅读 0 评论