首页
4K壁纸
直播
统计分析
友情链接
搜索
1
#1031 – TABLE STORAGE ENGINE FOR ” DOESN’T HAVE THIS OPTION解决方法
1,112 阅读
2
让浏览器不显示 https 页面中 http 请求警报 http-equiv=”Content-Security-Policy” content=”upgrade-insecure-requests”
845 阅读
3
报错代码:ERROR 1227 (42000)-解决办法
639 阅读
4
微信个人商户号养号建议
528 阅读
5
解决移动端position:fixed随软键盘移动的问题
479 阅读
PHP
Mysql
Linux
Reids
Java
常用笔记
学习
乱七八糟
Search
标签搜索
php
千卡云支付
Mysql
Linux
redis
千卡云
千卡易支付
Nginx
shell
JS
JSON
支付宝
CentOS
Apache
支付
function
database
fastadmin
phpstorm
快捷键
蓝科迪梦
累计撰写
69
篇文章
累计收到
0
条评论
首页
栏目
PHP
Mysql
Linux
Reids
Java
常用笔记
学习
乱七八糟
页面
4K壁纸
直播
统计分析
友情链接
搜索到
13
篇与
的结果
2025-03-10
php二维数组根据指定键值重新排序
/** * @Notes: * 二维数组根据指定键值重新排序 * @Interface arr_sort * @author [MengShuai] [<133814250@qq.com>] */ public static function arr_sort($arr,$field='id',$order='SORT_ASC'){ $sort = array( 'order' => $order, //排序顺序标志 SORT_DESC 降序;SORT_ASC 升序 'field' => $field, //排序字段 ); $arrSort = array(); foreach($arr AS $uniqid => $row){ foreach($row AS $key=>$value){ $arrSort[$key][$uniqid] = $value; } } if($sort['order']){ array_multisort($arrSort[$sort['field']], constant($sort['order']), $arr); } return $arr; } 测试数据: $userdb = array( 0 => array( 'uid' => 100, 'name' => 'Sandra Shush', 'url' => 'urlof100' ), 1 => array( 'uid' => 5465, 'name' => 'Stefanie Mcmohn', 'pic_square' => 'urlof100' ), ); 调用方法: $userdb = arr_sort($userdb,$field='uid',$order='SORT_DESC'); 打印方法: var_export($userdb); 打印结果: array ( 0 => array ( 'uid' => 5465, 'name' => 'Stefanie Mcmohn', 'pic_square' => 'urlof100', ), 1 => array ( 'uid' => 100, 'name' => 'Sandra Shush', 'url' => 'urlof100', ), )
2025年03月10日
27 阅读
0 评论
0 点赞
2025-03-07
PHP中register_shutdown_function函数的基础介绍与用法详解
1. 函数说明 定义:该函数是来注册一个会在PHP中止时执行的函数 参数说明: void register_shutdown_function ( callable $callback [, mixed $parameter [, mixed $... ]] ) 注册一个 callback ,它会在脚本执行完成或者 exit() 后被调用。 callback:待注册的中止回调 parameter:可以通过传入额外的参数来将参数传给中止函数 2. PHP中止的情况 PHP中止的情况有三种: 执行完成 exit/die导致的中止 发生致命错误中止 a. 第一种情况,执行完成 <?php function test() { echo '这个是中止方法test的输出'; } register_shutdown_function('test'); echo 'before' . PHP_EOL; 运行: before 这个是中止方法test的输出 注意:输出的顺序,等执行完成了之后才会去执行register_shutdown_function的中止方法test b. 第二种情况,exit/die导致的中止 <?php function test() { echo '这个是中止方法test的输出'; } register_shutdown_function('test'); echo 'before' . PHP_EOL; exit(); echo 'after' . PHP_EOL; 运行: before 这个是中止方法test的输出 后面的after并没有输出,即exit或者是die方法导致提前中止。 c. 第三种情况,发送致命错误中止 <?php function test() { echo '这个是中止方法test的输出'; } register_shutdown_function('test'); echo 'before' . PHP_EOL; // 这里会发生致命错误 $a = new a(); echo 'after' . PHP_EOL; 运行: before Fatal error: Uncaught Error: Class 'a' not found in D:\laragon\www\php_book\test.php on line 12 Error: Class 'a' not found in D:\laragon\www\php_book\test.php on line 12 Call Stack: 0.0020 360760 1. {main}() D:\laragon\www\php_book\test.php:0 这个是中止方法test的输出 后面的after也是没有输出,致命错误导致提前中止了。 3. 参数 第一个参数支持以数组的形式来调用类中的方法,第二个以及后面的参数都是可以当做额外的参数传给中止方法。 <?php class Shutdown { public function stop() { echo "这个是stop方法的输出"; } } // 当PHP终止的时候(执行完成或者是遇到致命错误中止的时候)会调用new Shutdown的stop方法 register_shutdown_function([new Shutdown(), 'stop']); // 将因为致命错误而中止 $a = new a(); // 这一句并没有执行,也没有输出 echo '必须终止'; 也可以在类中执行: <?php class TestDemo { public function __construct() { register_shutdown_function([$this, "f"], "hello"); } public function f($str) { echo "class TestDemo->f():" . $str; } } $demo = new TestDemo(); echo 'before' . PHP_EOL; /** 运行: before class TestDemo->f():hello */ 4. 同时调用多个 可以多次调用 register_shutdown_function,这些被注册的回调会按照他们注册时的顺序被依次调用。 不过注意的是,如果在第一个注册的中止方法里面调用exit方法或者是die方法的话,那么其他注册的中止回调也不会被调用。 代码: <?php /** * 可以多次调用 register_shutdown_function,这些被注册的回调会按照他们注册时的顺序被依次调用。 * 注意:如果你在f方法(第一个注册的方法)里面调用exit方法或者是die方法的话,那么其他注册的中止回调也不会被调用 */ /** * @param $str */ function f($str) { echo $str . PHP_EOL; // 如果下面调用exit方法或者是die方法的话,其他注册的中止回调不会被调用 // exit(); } // 注册第一个中止回调f方法 register_shutdown_function("f", "hello"); class TestDemo { public function __construct() { register_shutdown_function([$this, "f"], "hello"); } public function f($str) { echo "class TestDemo->f():" . $str; } } $demo = new TestDemo(); echo 'before' . PHP_EOL; /** 运行: before hello class TestDemo->f():hello 注意:如果f方法里面调用了exit或者是die的话,那么最后的class TestDemo->f():hello不会输出 */ 5. 用处 该函数的作用: 析构函数:在PHP4的时候,由于类不支持析构函数,所以这个函数经常用来模拟实现析构函数 致命错误的处理:使用该函数可以用来捕获致命错误并且在发生致命错误后恢复流程处理 代码如下: <?php /** * register_shutdown_function,注册一个会在php中止时执行的函数,中止的情况包括发生致命错误、die之后、exit之后、执行完成之后都会调用register_shutdown_function里面的函数 * Created by PhpStorm. * User: Administrator * Date: 2017/7/15 * Time: 17:41 */ class Shutdown { public function stop() { echo 'Begin.' . PHP_EOL; // 如果有发生错误(所有的错误,包括致命和非致命)的话,获取最后发生的错误 if (error_get_last()) { print_r(error_get_last()); } // ToDo:发生致命错误后恢复流程处理 // 中止后面的所有处理 die('Stop.'); } } // 当PHP终止的时候(执行完成或者是遇到致命错误中止的时候)会调用new Shutdown的stop方法 register_shutdown_function([new Shutdown(), 'stop']); // 将因为致命错误而中止 $a = new a(); // 这一句并没有执行,也没有输出 echo '必须终止'; 运行: Fatal error: Uncaught Error: Class 'a' not found in D:\laragon\www\php_book\1_23_register_shutdown.php on line 31 Error: Class 'a' not found in D:\laragon\www\php_book\1_23_register_shutdown.php on line 31 Call Stack: 0.0060 362712 1. {main}() D:\laragon\www\php_book\1_23_register_shutdown.php:0 Begin. Array ( [type] => 1 [message] => Uncaught Error: Class 'a' not found in D:\laragon\www\php_book\1_23_register_shutdown.php:31 Stack trace: #0 {main} thrown [file] => D:\laragon\www\php_book\1_23_register_shutdown.php [line] => 31 ) Stop. 注意:PHP7中新增了Throwable异常类,这个类可以捕获致命错误,即可以使用try...catch(Throwable $e)来捕获致命错误,代码如下: <?php try { // 将因为致命错误而中止 $a = new a(); // 这一句并没有执行,也没有输出 echo 'end'; } catch (Throwable $e) { print_r($e); echo $e->getMessage(); } 运行: Error Object ( [message:protected] => Class 'a' not found [string:Error:private] => [code:protected] => 0 [file:protected] => C:\laragon\www\php_book\throwable.php [line:protected] => 5 [trace:Error:private] => Array ( ) [previous:Error:private] => [xdebug_message] => Error: Class 'a' not found in C:\laragon\www\php_book\throwable.php on line 5 Call Stack: 0.0000 349856 1. {main}() C:\laragon\www\php_book\throwable.php:0 ) Class 'a' not found 这样的话,PHP7中使用Throwable来捕获的话比使用register_shutdown_function这个函数来得更方便,也更推荐Throwable。 注意:Error类也是可以捕获到致命错误,不过Error只能捕获致命错误,不能捕获异常Exception,而Throwable是可以捕获到错误和异常的,所以更推荐。 6.巧用register_shutdown_function判断php程序是否执行完 还有一种应用场景就是:要做一个消费队列,因为某条有问题的数据导致致命错误,如果这条数据不处理掉,那么整个队列都会导致瘫痪的状态,这样可以用以下方法来解决。即:如果捕获到有问题的数据导致错误,则在回调函数中将这条数据处理掉就可以了。 php范例参考与解析: <?php register_shutdown_function('myFun'); //放到最上面,不然如果下面有致命错误,就不会调用myFun了。 $execDone = false; //程序是否成功执行完(默认为false) /** ********************* 业务逻辑区************************* */ $tas = 3; if($tas == 3) { new daixiaorui(); } /** ********************* 业务逻辑结束************************* */ $execDone = true; //由于程序由上至下执行,因此当执行到此后,则证明逻辑没有出现致命的错误。 function myFun() { global $execDone; if($execDone === false) { file_put_contents("E:/myMsg.txt", date("Y-m-d H:i:s")."---error: 程序执行出错。\r\n", FILE_APPEND); /******** 以下可以做一些处理 ********/ } } 总结 register_shutdown_function这个函数主要是用在处理致命错误的后续处理上(PHP7更推荐使用Throwable来处理致命错误),不过缺点也很明显,只能处理致命错误Fatal error,其他的错误包括最高错误Parse error也是没办法处理的。
2025年03月07日
38 阅读
0 评论
0 点赞
2023-08-01
include和require的区别
首先include和require都是引入指定的文件。_once表示只引入一次,已经引入过一次的文件接下来就不会再引入。 例如在【index.php】中 <?php echo '最爱PHP'; ?> 运行下面的程序代码 复制代码 <?php include 'index.php'; require 'index.php'; include_once 'index.php'; require_once 'index.php'; ?> 复制代码 输出的结果会是:最爱PHP最爱PHP,如果将_once引入的语句放在include和require上面,结果将是:最爱PHP最爱PHP最爱PHP最爱PHP。 1、加载失败的处理方式不同 include与require除了在处理引入文件的方式不同外,最大的区别就是: include在引入不存文件时产生一个警告且脚本还会继续执行, require则会导致一个致命性错误且脚本停止执行。 <?php include 'hello.php'; echo 'world'; ?> 如果hello.php不存在,echo ‘world’这句是可以继续执行的。 <?php require 'hello.php'; echo 'world'; ?> 如果hello.php不存在,echo ‘hello’这句是不会执行的,到require时就停止了。 2、include()是有条件包含函数,而 require()则是无条件包含函数 复制代码 <?php if(FALSE){ include 'file.php'; //file.php不会被引入 } if(FALSE){ require 'file.php'; //file.php将会被引入 } ?> 复制代码 3、文件引用方式 include有返回值,而require没有 复制代码 <?php $retVal = include(’somefile.php’); if(!empty($retVal)){ echo "文件包含成功"; }else{ echo "文件包含失败"; } ?> 复制代码 include()执行时需要引用的文件每次都要进行读取和评估, require()执行时需要引用的文件只处理一次(实际上执行时需要引用的文件内容替换了require()语句) 可以看出若有包含这些指令之一的代码和可能执行多次的代码,则使用require()效率比较高, 若每次执行代码时相读取不同的文件或者有通过一组文件叠代的循环,就使用include(), require通常使用方法,这个函数通常放在 PHP 程序的最前面,PHP 程序在执行前,就会先读入 require 所指定引入的文件,使它变成 PHP 程序网页的一部份。常用的函数,亦可以这个方法将它引入网页中。 include通常使用方法,这个函数一般是放在流程控制的处理部分中。PHP 程序网页在读到 include 的文件时,才将它读进来。这种方式,可以把程序执行时的流程简单化 另外关于include和require后面是否加括号的问题, 理论上来说:include和require后面加不加括号对执行结果没有区别,但是加上括号效率较低,所以后面能不加括号就不加括号。
2023年08月01日
170 阅读
0 评论
0 点赞
2023-08-01
php 类静态变量 和 常量消耗内存及时间对比
在对类执行100w次循环后, 常量最快,变量其次,静态变量消耗时间最高 其中: 常量消耗:101.1739毫秒 变量消耗:2039.7689毫秒 静态变量消耗:4084.8911毫秒 class Timer_profiler { public static $begin_timer; public static $finish_timer; public static $timer_html; /** * 计算时间差 * @return type */ public static function getRecordTimer() { return (self::getFinishTimer() - self::getBeginTimer()) * 1000; } /** * 生成输出HTML * @param type $message * @return type */ public static function recordHtml($message = '') { self::setFinishTimer(); return "<p>{$message}耗时: " . self::getRecordTimer() . " 毫秒</p>"; } /** * 设置开始时间 */ public static function setBeginTimer() { self::$begin_timer = self::getTime(); } /** * 设置结束时间 */ public static function setFinishTimer() { self::$finish_timer = self::getTime(); } /** * 获取开始时间 * @return type */ public static function getBeginTimer() { return self::$begin_timer; } /** * 获取结束时间 * @return type */ public static function getFinishTimer() { return self::$finish_timer; } /** * 获取带微妙的时间戳 * @return type */ private static function getTime() { list($usec, $sec) = explode(" ", microtime()); return (number_format($sec+$usec,6,'.', '')); } } function computeTime($otime,$message){ return; $ntime = xdebug_time_index(); $str = ''; $str .= $message . ($ntime*1000-$otime*1000); $str .= "<br>"; echo $str; } function getMemoryUsed(){ $str = '消耗内存<h3 style="color:red"> '; $str .= round(memory_get_usage()/1024/1024, 4).'MB'; $str .= '</h3>'; echo $str; } $count_i = 100*10000; //$count_i = 100000; Timer_profiler::setBeginTimer(); computeTime(xdebug_time_index(),'开始执行'); echo Timer_profiler::recordHtml('开始执行'); getMemoryUsed(); class TestVar { public $A1 = 'aaaaaaaaaaaaaaaaa'; public $A2 = 'aaaaaaaaaaaaaaaaa'; public $A3 = 'aaaaaaaaaaaaaaaaa'; public $A4 = 'aaaaaaaaaaaaaaaaa'; public $A5 = 'aaaaaaaaaaaaaaaaa'; public $A6 = 'aaaaaaaaaaaaaaaaa'; public $A7 = 'aaaaaaaaaaaaaaaaa'; public $A8 = 'aaaaaaaaaaaaaaaaa'; } $TestVar = new TestVar(); for($i=0;$i<=$count_i;$i++){ $t = $TestVar->A1; $t = $TestVar->A2; $t = $TestVar->A3; $t = $TestVar->A4; $t = $TestVar->A5; $t = $TestVar->A6; $t = $TestVar->A7; $t = $TestVar->A8; } getMemoryUsed(); echo Timer_profiler::recordHtml('变量完成'); computeTime(xdebug_time_index(),'变量完成'); Timer_profiler::setBeginTimer(); class TestStaticVar { static $A1 = 'aaaaaaaaaaaaaaaaa'; static $A2 = 'aaaaaaaaaaaaaaaaa'; static $A3 = 'aaaaaaaaaaaaaaaaa'; static $A4 = 'aaaaaaaaaaaaaaaaa'; static $A5 = 'aaaaaaaaaaaaaaaaa'; static $A6 = 'aaaaaaaaaaaaaaaaa'; static $A7 = 'aaaaaaaaaaaaaaaaa'; static $A8 = 'aaaaaaaaaaaaaaaaa'; } for($i=0;$i<=$count_i;$i++){ $t = TestStaticVar::$A1; $t = TestStaticVar::$A2; $t = TestStaticVar::$A3; $t = TestStaticVar::$A4; $t = TestStaticVar::$A5; $t = TestStaticVar::$A6; $t = TestStaticVar::$A7; $t = TestStaticVar::$A8; } getMemoryUsed(); echo Timer_profiler::recordHtml('静态变量完成'); computeTime(xdebug_time_index(),'静态变量完成'); Timer_profiler::setBeginTimer(); class TestConstVar { const A1 = 'aaaaaaaaaaaaaaaaa'; const A2 = 'aaaaaaaaaaaaaaaaa'; const A3 = 'aaaaaaaaaaaaaaaaa'; const A4 = 'aaaaaaaaaaaaaaaaa'; const A5 = 'aaaaaaaaaaaaaaaaa'; const A6 = 'aaaaaaaaaaaaaaaaa'; const A7 = 'aaaaaaaaaaaaaaaaa'; const A8 = 'aaaaaaaaaaaaaaaaa'; } for($i=0;$i<=$count_i;$i++){ $t = TestConstVar::A1; $t = TestConstVar::A2; $t = TestConstVar::A3; $t = TestConstVar::A4; $t = TestConstVar::A5; $t = TestConstVar::A6; $t = TestConstVar::A7; $t = TestConstVar::A8; } getMemoryUsed(); echo Timer_profiler::recordHtml('常量完成'); computeTime(xdebug_time_index(),'常量完成'); //echo Timer_profiler::recordHtml('共执行'); computeTime(xdebug_time_index(),'共执行'); exit;
2023年08月01日
201 阅读
0 评论
0 点赞
2023-08-01
php中的clone()方法
php5中默认通过引用传递对象,假设$obj1和$obj2是两个对象,使用$obj2=$obj1这样的方法复制出来的对象是相关联的,如果在程序中需要复制出一个值和原来相同的对象又不希望复制出来的对象与源对象相关联,那么就需要使用clone关键字,类似于$obj2=clone $obj1; 如果还希望在复制的同时,目标对象的某些属性与源对象的不同,可以在类里面定义一个__clone()方法,在这个方法中完成为目标对象的属性赋新值。 <?php class doclone{ private $id,$name,$address; public function __construct($id=0,$name='',$address=''){ $this->name=$name; $this->id=$id; $this->address=$address; } public function get_id(){ return $this->id; } public function get_name(){ return $this->name; } public function get_address(){ return $this->address; } public function __clone(){ $this->id=$this->id+1; $this->name='Kong'; $this->address='USA'; } } $A = new doclone(10,'A','UK'); echo '克隆之前的对象:'; echo 'id='.$A->get_id(); echo 'name='.$A->get_name(); echo 'address='.$A->get_address(); echo "\n"; $B = clone $A; echo '克隆过后的对象:'; echo 'id='.$A->get_id(); echo 'name='.$A->get_name(); echo 'address='.$A->get_address(); echo "\n"; echo '克隆过后的对象属性:'; echo 'id='.$B->get_id(); echo 'name='.$B->get_name(); echo 'address='.$B->get_address();
2023年08月01日
249 阅读
0 评论
0 点赞
2023-08-01
Expected response code 220 but got code “” with message “”
如题,在使用laravel时,mail按照配置阿里云邮箱 .env配置: MAIL_DRIVER=smtp MAIL_HOST=smtpdm.aliyun.com MAIL_PORT=465 MAIL_USERNAME=ali@mail.qvnidaye.com MAIL_PASSWORD=** MAIL_FROM_ADDRESS=ali@mail.qvnidaye.com MAIL_FROM_NAME=鼎云网络 MAIL_ENCRYPTION=SSL 发送邮件报错: Expected response code 220 but got code "", with message """ 解决办法: 找到config/mail.php 更改:'encryption' => env('MAIL_ENCRYPTION', 'tls'), 再次发送测试邮件,发送成功。 这个一般是由于encyption配置导致的 Secure Sockets Layer (SSL) Transport Layer Security (TLS) 如果使用ssl端口则encyption配置项必须为465/994如果使用非ssl则应该使用25
2023年08月01日
235 阅读
0 评论
0 点赞
2023-08-01
PHP Fatal error: Class 'Memcache' not found in
安装了memcached和php的memcache的扩展,PHPinfo()也支持了memcache, 但是放在项目中就提示Class"Memcache" not found, 最后发现php7.3装的是memcached,多节点的 然后更换了php7.1重新配置了memcache之后正常运行
2023年08月01日
236 阅读
0 评论
0 点赞
2023-04-18
PHP在数组中追加列
/* model实例化*/ $list = self::where($where) ->with(['user''node']) ->alias('log') ->field('log.idlog.user_idlog.rate(log.u + log.d) as origin_trafficlog.trafficlog.log_timelog.node_id') ->order($order) ->paginate([ 'query' => Request::get() 'list_rows' => $pageSize ]); $ids = $list->toarray(); //重新的整理数组 $ids = array_values(array_column($ids["data"]'daili_code')); //获取数组中指定列,并去除键名 $ids = implode("" $ids); //格式化数组 /* 空值处理 */ if(!$ids){ $ids=[]; array_push($ids'0'); } $daili = Db::name('app_daili')->where('daili_code''in'$ids)->field('name')->select(); //输出
2023年04月18日
233 阅读
0 评论
0 点赞
2023-04-18
php-redis Deprecated: Function Redis::setTimeout() is deprecated in
Deprecated: Function Redis::setTimeout() is deprecated in Deprecated 意思是不推荐,但仍然可以使用,是级别最低的报错 这是php7.0版本以后redis的错误提示 关闭此类报错只需到php.ini 修改参数 error_reporting = E_ALL &~E_NOTICE &~E_DEPRECATED 然后重启php服务就行了 但是Deprecated类报错会影响性能,最好是将不推荐的函数替换掉 https://segmentfault.com/a/1190000002880738 php-redis常用函数操作类 https://blog.csdn.net/haige025/article/details/97794504
2023年04月18日
259 阅读
0 评论
0 点赞
2022-12-24
php报错:Cannot redeclare class 提示的解决方法
1.重复包含相同的类文件: 例如:对于某个类文件zuimoban.php,在a.php中 include "zuimoban.php"; 在b.php中 include "a.php"; include "zuimoban.php"; 就会报错。 解决:将上述的include全部替换为include_once,同理使用require导入方法时则全部替换为require_once即可。 include和require的区别:http://bbb.ms521.cn/index.php/Home/Index/article/aid/65 2.在同一个文件中重复声明了两次同名的类: 例如: <?php class Foo {} class Foo {} ?> 在第二个 Foo 的地方就会报错。 解决:去掉第二个Foo,或者重命名。 为了防止重复定义,可以在定义一个新的类的时候判断一下这个类是否已经存在: <?php if(class_exists('SomeClass') != true) {} ?> 3.该类为PHP类库中内置的类。 判断方法:在一个空文件中写入 <?php class Com {} ?> 这时候提示Cannot redeclare class Com,说明这个类就是PHP内置的类。不能使用。 另外,要避免使用太大众化的类名,比如Com,这个类在Linux使用可能是正常的,在Windows环境却无法运行
2022年12月24日
233 阅读
0 评论
0 点赞
2022-12-24
php-redis Deprecated: Function Redis::setTimeout() is deprecated in
Deprecated: Function Redis::setTimeout() is deprecated in Deprecated 意思是不推荐,但仍然可以使用,是级别最低的报错 这是php7.0版本以后redis的错误提示 关闭此类报错只到php.ini 修改参数 error_reporting = E_ALL &~E_NOTICE &~E_DEPRECATED 然后重启php服务就行了 但是Deprecated类报错会影响性能,最好是将不推荐的函数替换掉
2022年12月24日
269 阅读
0 评论
0 点赞
2022-12-16
PHP在数组中追加列
/* model实例化*/ $list = self::where($where) ->with(['user''node']) ->alias('log') ->field('log.idlog.user_idlog.rate(log.u + log.d) as origin_trafficlog.trafficlog.log_timelog.node_id') ->order($order) ->paginate([ 'query' => Request::get() 'list_rows' => $pageSize ]); $ids = $list->toarray(); //重新的整理数组 $ids = array_values(array_column($ids["data"]'daili_code')); //获取数组中指定列,并去除键名 $ids = implode("" $ids); //格式化数组 /* 空值处理 */ if(!$ids){ $ids=[]; array_push($ids'0'); } $daili = Db::name('app_daili')->where('daili_code''in'$ids)->field('name')->select(); //输出
2022年12月16日
286 阅读
0 评论
0 点赞
2022-09-25
js前端和php后端对url编解码处理方式不一致的问题
问题:php的解码方式是urldecode,前端的编码方式有escape,encodeURI,encodeURIComponent这三种,escape出来的url,php可以正常解析出来,但是escape不支持ES6,其他两种方式php不能解析正确 解决方法一,根据情况转: URI部分用encodeURI,参数部分用encodeURIComponent,这样才是相对完美的编码方式。 比如`https://example.com/?next=abc...`,得到的结果分别是: encodeURI(`https://example.com/?next=abc...`): "https://example.com/?next=abc.com/def&encoding=utf-8" encodeURIComponent(`https://example.com/?next=abc...`): "https%3A%2F%2Fexample.com%2F%3Fnext%3Dabc.com%2Fdef%26encoding%3Dutf-8" encodeURI(https://example.com/?next=${encodeURIComponent('abc.com/def')}&encoding=${encodeURIComponent('utf-8')}): "https://example.com/?next=abc.com%252Fdef&encoding=utf-8" 解决方法二,base64: json_encode()用eval()还原 base64_decode()用base64_encode()还原 解决方法三,最简单的方法,前后端都不使用转义!
2022年09月25日
212 阅读
0 评论
0 点赞