最近把一個ecshop程序做的網站轉移到一臺php5.5版本的服務器上,由于之前的網站模板做過修改,不兼容php7,所以選擇使用低版本的php服務器,然而從php5.3.28轉到php5.5g還是遇到了問題,出現很多的Deprecated: preg_replace()錯誤,怎么辦?由于自己不做開發,但做seo時間還是比較久,這點相對來說還是難不倒我,百度就是最好的老師,你所遇到的絕大部分問題百度上其他網友都已給出了答案,所以只要你認真產找一般都能找到。
對于參加了seo培訓的學員,你學習的目的就是要把網站的關鍵詞seo到百度搜索結果首頁,所以和百度打交道是必須的,那么我們就要很好的利用百度,熟悉百度,從而在使用的過程中總結百度的一些排名規律,把這些規律做為我們seo的一個輔助項。費話不多說,我從網站找到很多條答案,有的只有一兩條管用,有的干脆就不管用,這應該取決于當時發布者所使用的服務器php版本和我使用的有區別的原因吧,總之能夠把自己遇到問題解決的方法分享出來,這些都應該成為我們的老師。
下面我把ecshop2.7.3針對php5.5版本出現的錯誤解決方法分享出來,以提供給遇到我同樣錯誤的seo人員解決遇到的問題。
Deprecated: preg_replace() 之類的報錯最多,要修改的文件路徑:includes/cls_template.php
如果你的PHP版本恰好是PHP5.5.X,那你的ECSHOP肯定就會報類似下面這樣的錯誤:
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in......
解決辦法:
1. Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in \includes\cls_template.php on line 300
原有內容:
return preg_replace("/{([^\}\{]*)}/e", "\$this->select('\\1');", $source);
修改后內容:
return preg_replace_callback("/{([^\}\{]*)}/", function($r) { return $this->select($r[1]); }, $source);
2. Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in \includes\cls_template.php on line 491
原有內容:
$out = "<?php " . '$k = ' . preg_replace("/(\'\\$[^,] )/e" , "stripslashes(trim('\\1','\''));", var_export($t, true)) . ";";
修改后內容:
$out = "<?php " . '$k = ' . preg_replace_callback("/(\'\\$[^,] )/" , function($match){return stripslashes(trim($match[1],'\''));}, var_export($t, true)) . ";"
3. Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in \includes\cls_template.php on line 550
原有內容:
$val = preg_replace("/\[([^\[\]]*)\]/eis", "'.'.str_replace('$','\$','\\1')", $val);
修改后內容:
$val = preg_replace_callback('/\[([^\[\]]*)\]/is',function ($matches) {return '.'.str_replace('$','\$',$matches[1]);},$val);
4. Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in \includes\cls_template.php on line 1074
原有內容:
$pattern = '/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/se';
$replacement = "'{include file='.strtolower('\\1'). '}'";
$source = preg_replace($pattern, $replacement, $source);
修改后內容:
$pattern = '/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/s';
$source = preg_replace_callback($pattern, function($r){return '{include file='.strtolower($r[1]). '}';}, $source);
5. Strict Standards: Only variables should be passed by reference in ...\upload\includes\lib_main.php on line 1329
原有內容:
$ext = end(explode('.', $tmp));
修改后內容:
$extsub = explode('.', $tmp);
$tmp = end($extsub);
$tmp = basename($tmp,".$ext");
最后,將錯誤修改后,上傳到服務器.然后進入后臺,清空緩存,刷新頁面即可。
建議修改前,做文件備份,以防止修改錯誤導致網站打不開~