[PHP] PHP7已經刪除了preg_replace的e修飾符


官網提示是這樣的,對/e修飾符的支持已刪除。請改用preg_replace_callback()
原因是/e 修正符使 preg_replace() 將 replacement 參數當作 PHP 代碼(在適當的逆向引用替換完之后),會被一句話后門使用

 

看看smarty中是也是這樣用的,也是存在問題
$source_content = preg_replace($search.'e', "'"
. $this->_quote_replace($this->left_delimiter) . 'php'
. "' . str_repeat(\"\n\", substr_count('\\0', \"\n\")) .'"
. $this->_quote_replace($this->right_delimiter)
. "'"
, $source_content);
可以把smarty模板修改成這個
$source_content = preg_replace_callback($search, function ($matches){
$str="";
$str.=$this->_quote_replace($this->left_delimiter) . 'php';
$str.=str_repeat("\\n\\", substr_count($matches[1], "\\n\\"));
$str.=$this->_quote_replace($this->right_delimiter);
return $str;
}, $source_content);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM