一、在PHP7中,preg_replace不能用/e修饰符,所以用preg_replace_callback代替preg_replace,

需要修改的文件包括

ThinkPHP\Lib\Template\ThinkTemplate.class.php

ThinkPHP\Lib\Core\Dispatcher.class.php

ThinkPHP\Lib\Core\Db.class.php

ThinkPHP\Lib\Behavior\CheckRouteBehavior.class.php

ThinkPHP\Extend\Mode\Lite\Dispatcher.class.php

ThinkPHP\Lib\Behavior\ReadHtmlCacheBehavior.class.php

ThinkPHP\Common\common.php

1)ThinkPHP\Lib\Template\ThinkTemplate.class.php

这个文件大约需要修改8处地方

NO1. 大约在137行,将

[php] view plain copy

$tmplContent = preg_replace(‘//eis’,"\$this->restoreLiteral(‘\\1′)",$tmplContent);

替换为

[php] view plain copy

$tmplContent = preg_replace_callback(‘//is’, function($r) {

return $this->restoreLiteral($r[1]);

}, $tmplContent);

NO2. 大约在168行,将

[php] view plain copy

$content = preg_replace(‘/’.$begin.’literal’.$end.’(.*?)’.$begin.’\/literal’.$end.’/eis’,"\$this->parseLiteral(‘\\1′)",$content);

替换为

[php] view plain copy

$content = preg_replace_callback(‘/’ . $begin . ‘literal’ . $end . ‘(.*?)’ . $begin . ‘\/literal’ . $end . ‘/is’, function($r) {

return $this->parseLiteral($r[1]);

}, $content);

NO3. 大约在197行,将

[php] view plain copy

$content = preg_replace(‘/(‘.$this->config['tmpl_begin'].’)([^\d\s'.$this->config['tmpl_begin'].$this->config['tmpl_end'].’].+?)(‘.$this->config['tmpl_end'].’)/eis’,"\$this->parseTag(‘\\2′)",$content);

替换为

[php] view plain copy

$content = preg_replace_callback(‘/(‘ . $this->config['tmpl_begin'] . ‘)([^\d\s' . $this->config['tmpl_begin'] . $this->config['tmpl_end'] . ‘].+?)(‘ . $this->config['tmpl_end'] . ‘)/is’, function($r) {

return $this->parseTag($r[2]);

}, $content);

NO4. 大约在266行,将

[php] view plain copy

preg_replace(‘/’.$begin.’block\sname=(.+?)\s*?’.$end.’(.*?)’.$begin.’\/block’.$end.’/eis’,"\$this->parseBlock(‘\\1′,’\\2′)",$content);

替换为

[php] view plain copy

preg_replace_callback(‘/’ . $begin . ‘block\sname=(.+?)\s*?’ . $end . ‘(.*?)’ . $begin . ‘\/block’ . $end . ‘/is’, function ($r) {

$this->parseBlock($r[1], $r[2]);

}, $content);

NO5. 大约在271行,将

[php] view plain copy

$content = preg_replace(‘/’.$begin.’block\sname=(.+?)\s*?’.$end.’(.*?)’.$begin.’\/block’.$end.’/eis’,"\$this->replaceBlock(‘\\1′,’\\2′)",$content);

替换为

[php] view plain copy

$content = preg_replace_callback(‘/’ . $begin . ‘block\sname=(.+?)\s*?’ . $end . ‘(.*?)’ . $begin . ‘\/block’ . $end . ‘/is’, function ($r) {

return $this->replaceBlock($r[1], $r[2]);

}, $content);

NO6. 大约在273行,将

[php] view plain copy

$content = preg_replace(‘/’.$begin.’block\sname=(.+?)\s*?’.$end.’(.*?)’.$begin.’\/block’.$end.’/eis’,"stripslashes(‘\\2′)",$content);

替换为

[php] view plain copy

$content = preg_replace_callback(‘/’ . $begin . ‘block\sname=(.+?)\s*?’ . $end . ‘(.*?)’ . $begin . ‘\/block’ . $end . ‘/is’, function ($r) {

return stripslashes($r[2]);

}, $content);

NO7和NO8,这两处是连在一起的 大约在396行,改成如下:

[php] view plain copy

if (!$closeTag){

$patterns = ‘/’.$begin.$parseTag.$n1.’\/(\s*?)’.$end.’/is’;

$replacement = "\$this->parseXmlTag(‘$tagLib’,'$tag’,'$1′,”)";

$content = preg_replace_callback($patterns, function($r) use($tagLib, $tag) {

return $this->parseXmlTag($tagLib, $tag, $r[1], ”);

},$content);

}else{

$patterns = ‘/’.$begin.$parseTag.$n1.$end.’(.*?)’.$begin.’\/’.$parseTag.’(\s*?)’.$end.’/is’;

$replacement = "\$this->parseXmlTag(‘$tagLib’,'$tag’,'$1′,’$2′)";

for($i=0;$i

$content = preg_replace_callback($patterns, function($r) use($tagLib, $tag) {

return $this->parseXmlTag($tagLib, $tag, $r[1], $r[2]);

},$content);

}

2)ThinkPHP\Lib\Core\Dispatcher.class.php

大约132行,将

[php] view plain copy

preg_replace(‘@(\w+)\/([^\/]+)@e’, ‘$var[\'\\1\']=strip_tags(\’\\2\’);’, implode(‘/’,$paths));

改为

[php] view plain copy

preg_replace_callback(‘@(\w+)\/([^\/]+)@’,function($r) use (&$var){

$var[$r['1']] = strip_tags($r[2]);

},implode(‘/’,$paths));

3)ThinkPHP\Lib\Core\Db.class.php

大约605行,将

[php] view plain copy

$joinStr = preg_replace("/__([A-Z_-]+)__/esU",C("DB_PREFIX").".strtolower(‘$1′)",$joinStr);

改为

[php] view plain copy

$DB_PREFIX = C("DB_PREFIX");

$joinStr = preg_replace_callback("/__([A-Z_-]+)__/sU",function ($r) use($DB_PREFIX) {

return $DB_PREFIX.".strtolower({$r[1]})";

},$joinStr);

4)ThinkPHP\Lib\Behavior\CheckRouteBehavior.class.php

这个文件需要修改的地方共4处

NO1. 大约151行,将

[php] view plain copy

$url = preg_replace(‘/:(\d+)/e’,'$values[\\1-1]‘,$url);

改为

[php] view plain copy

$url = preg_replace_callback(‘/:(\d+)/’,function($r) use (&$values){

return $values[$r[1]-1];

},$url);

NO2. 大约168行,将

[php] view plain copy

preg_replace(‘@(\w+)\/([^\/]+)@e’, ‘$var[strtolower(\'\\1\')]=strip_tags(\’\\2\’);’, implode(‘/’,$paths));

改为

[php] view plain copy

preg_replace_callback(‘@(\w+)\/([^\/]+)@’,function($r) use (&$var){

$var[strtolower($r['1'])] = strip_tags($r[2]);

},implode(‘/’,$paths));

NO3. 大约191行,将

[php] view plain copy

$url = preg_replace(‘/:(\d+)/e’,'$matches[\\1]‘,$url);

改为

[php] view plain copy

$url = preg_replace_callback(‘/:(\d+)/’, function($r) use (&$matches) {

return $matches[$r[1]];

},$url);

NO4. 大约201行,将

[php] view plain copy

preg_replace(‘@(\w+)\/([^,\/]+)@e’, ‘$var[strtolower(\'\\1\')]=strip_tags(\’\\2\’);’, $regx);

改为

[php] view plain copy

preg_replace_callback(‘@(\w+)\/([^,\/]+)@’,function($r) use (&$var){

$var[strtolower($r['1'])] = strip_tags($r[2]);

},$regx);

5)ThinkPHP\Extend\Mode\Lite\Dispatcher.class.php

大约65行,将

[php] view plain copy

$res = preg_replace(‘@(\w+)’.$depr.’([^'.$depr.'\/]+)@e’, ‘$var[\'\\1\']="\\2";’, implode($depr,$paths));

改为

[php] view plain copy

preg_replace_callback(‘@(\w+)’.$depr.’([^'.$depr.'\/]+)@’,function($r) use (&$var){

$var[$r['1']] = $r[2];

},implode($depr,$paths));

6)ThinkPHP\Lib\Behavior\ReadHtmlCacheBehavior.class.php

大约65行处的一个if判断替换为:

[php] view plain copy

if(!empty($html)) {

// 解读静态规则

$rule = $html[0];

// 以$_开头的系统变量

//$rule = preg_replace(‘/{\$(_\w+)\.(\w+)\|(\w+)}/e’,"\\3(\$\\1['\\2'])",$rule);

$rule = preg_replace_callback(‘/{\$(_\w+)\.(\w+)\|(\w+)}/’,function($r){

$system = "$r[3](\${$r[1]}['$r[2]‘])";

eval( "\$system = $system ;" );

return $system;

},$rule);

//$rule = preg_replace(‘/{\$(_\w+)\.(\w+)}/e’,"\$\\1['\\2']",$rule);

$rule = preg_replace_callback(‘/{\$(_\w+)\.(\w+)}/’,function($r){

$system = "\${$r[1]}['$r[2]‘]";

eval( "\$system = $system ;" );

return $system;

},$rule);

// {ID|FUN} GET变量的简写

//$rule = preg_replace(‘/{(\w+)\|(\w+)}/e’,"\\2(\$_GET['\\1'])",$rule);

$rule = preg_replace_callback(‘/{(\w+)\|(\w+)}/’,function($r){

return $r[2]($_GET[$r[1]]);

},$rule);

//$rule = preg_replace(‘/{(\w+)}/e’,"\$_GET['\\1']",$rule);

$rule = preg_replace_callback(‘/{(\w+)}/’,function($r){

return $_GET[$r[1]];

},$rule);

// 特殊系统变量

$rule = str_ireplace(

array(‘{:app}’,'{:module}’,'{:action}’,'{:group}’),

array(APP_NAME,MODULE_NAME,ACTION_NAME,defined(‘GROUP_NAME’)?GROUP_NAME:”),

$rule);

// {|FUN} 单独使用函数

//$rule = preg_replace(‘/{\|(\w+)}/e’,"\\1()",$rule);

$rule = preg_replace_callback(‘/{\|(\w+)}/’,function($r){

return $r[1]();

},$rule);

if(!empty($html[2])) $rule = $html[2]($rule); // 应用附加函数

$cacheTime = isset($html[1])?$html[1]:C(‘HTML_CACHE_TIME’); // 缓存有效期

// 当前缓存文件

define(‘HTML_FILE_NAME’,HTML_PATH . $rule.C(‘HTML_FILE_SUFFIX’));

return $cacheTime;

}

7)ThinkPHP\Common\common.php

大约217行,将

return ucfirst(preg_replace("/_([a-zA-Z])/e", "strtoupper(‘\\1′)", $name));

改为

$str = preg_replace_callback(‘/_([a-zA-Z])/’, function($r) {

return strtoupper($r[1]);

}, $name);

return ucfirst($str);

二、如果有用到验证码,请把ThinkPHP\Extend\Library\ORG\Util目录下的String.class.php复制一份放在一起,并改名为Stringnew.class.php

打开Stringnew.class.php

把所有的String::替换为Stringnew::

并把类名Class String 改为 Class Stringnew

打开ThinkPHP\Extend\Library\ORG\Util\Image.class.php,把所有的

[php] view plain copy

import(‘ORG.Util.String’);

替换成

[php] view plain copy

import(‘ORG.Util.Stringnew’);

三、自定义函数的参数最好给定默认值,如果自定义函数规定了参数,但是没有指定默认值,在外部调用的时候,如果传参的时候少传值了,那么运行会报错!

这样,在PHP7下就能运行ThinkPHP3.1了。

thinkphp3.1迁移php7,ThinkPHP3.1迁移到PHP7相关推荐

  1. mysql大表迁移_MySQL 大表迁移

    一.需求分析 线上100G 大表 table1 迁移,从DB1 迁移到DB2. 二.环境要求: 1.MySQL 使用InnoDB 存储引擎,且开启独立表空间: 2.两个库的MySQL版本一致(未做不同 ...

  2. 数据库迁移_【干货分享】DM数据库迁移方法(物理迁移)

    在数据库的维护过程中,可能涉及换服务器,或者需要现网数据库环境测试的情况,这时,最简单快速的办法就是将源数据库相关的文件拷贝到目标主机,然后注册数据库实例服务.这就是数据库的物理迁移过程,可以是从wi ...

  3. 利用迁移助手从Oracle迁移到SQL Server

    在实际的项目中,我们常常需要在不同的数据库之前进行迁移,在以前,这可能是和麻烦的事情,但是现在有很多的好的工具可以快速的帮助我们忙成这个目标. 下面我们从来看看如何从Oracle迁移到SQL Serv ...

  4. 共享文件服务器迁移,服务器共享文件夹迁移

    服务器共享文件夹迁移 内容精选 换一换 SQL Server使用日志传送来进行灾备,即可以自动将主服务器上数据库实例的事务日志发送到辅助服务器上,用于灾备的数据库实例进行还原操作.如图1所示的方案中, ...

  5. thinkphp3.1迁移php7,ThinkPHP3.1迁移到PHP7的注意事项

    ThinkPHP3.1迁移到PHP7的注意事项 2018.10.31 3723 小平 ThinkPHP3.1迁移到PHP7的注意事项 最近项目从PHP5.5升级到了PHP7.0,框架是ThinkPHP ...

  6. KVM 虚拟机在物理主机之间迁移的实现 -- 静态迁移/动态迁移/存储迁移

    原文转自:http://www.ibm.com/developerworks/cn/linux/l-cn-mgrtvm2/ 静态迁移 静态迁移:也叫做常规迁移.离线迁移(Offline Migrati ...

  7. ecs服务器数据迁移_免费服务器迁移上云实践分享!一键迁云,自动同步

    导读:云服务器ECS(Elastic Computing Service)是每个阿里云用户上云的"第一步". 本次分享将为大家介绍免费的服务器迁移上云最佳实践方案和新功能特性,包括 ...

  8. drupal 迁移_关于如何迁移到Drupal的4个技巧

    drupal 迁移 如果您的网站内容丰富,那么您肯定会听说过Drupal ,这是一个开源内容管理系统(CMS). 也许您还听说过Drupal是免费的,安全的,并且拥有完善的开发人员网络,这意味着有很多 ...

  9. yii 执行指定迁移文件_laravel的迁移文件

    1. 迁移是什么? 迁移就像是对数据库进行的版本控制,让你的团队能够轻松地去定义和共享程序的数据库结构.迁移通常配合 Laravel 的结构生成器,可以轻松生成应用程序的数据库结构.如果团队中有个成员 ...

  10. 服务器项目迁移本地,云服务器迁移本地

    云服务器迁移本地 内容精选 换一换 迁移前,若选择迁移到已有服务器,请做以下准备工作:需配置目的端服务器所在VPC安全组,如果是Windows系统需要开放TCP的8899端口.8900端口和22端口: ...

最新文章

  1. Another ORA-00600 internal error
  2. px4原生源码学习一
  3. n个点组成多少个三角形Java,农田开发 NOJ (已知N个点选取3个求最大三角形面积问题)...
  4. Unity-Find-Script-References 查找脚本的引用
  5. Flink应用实战案例50篇(五)-Apache Flink 在 bilibili 的多元化探索与实践
  6. jquery ajax json转换出错Invalid JSON
  7. 离线计算中的幂等和DataWorks中的相关事项
  8. rm 使用正则表达式 删除文件
  9. 1.mongoDB 简介
  10. [MapReduce_8] MapReduce 中的自定义分区实现
  11. java对接芯烨XP58系列打印机,网络驱动
  12. js打开新页面的几种方式
  13. 接口测试平台代码实现11: 用户管理模块设计和开发
  14. 一级域名、二级域名 cookie
  15. 一台计算机安装几个操作系统,电脑装3个系统-一台电脑可以安装几个操作系统?...
  16. 数据库驱动和JDBC、DBCP-C3P0连接池
  17. 基于惯性轮倒立摆原理的自行车
  18. ncl如何添加线shp文件_NCL画图个例讲解.pdf
  19. vmware_无法连接虚拟机vmx提前退出
  20. Hangfire 使用笔记

热门文章

  1. 为什么要用Handler,怎么用Handler
  2. 深度学习不得不知的英文名称
  3. WIFI-TTL透传模块
  4. 【win10】windows音频设备图形隔离占CPU高解决办法
  5. 面试问烂了的测试用例: 登录界面的测试用例
  6. SecureCRT中文乱码解决(汇总)
  7. ContentProvider使用Demo
  8. 转【JMeter】--JMeter下载及使用
  9. 利用window.location实现下载文档
  10. Linux系列讲解 —— SSH登录