A-A+

php 5.x 版本preg_replace 转换为 php 7.x 版本preg_replace_callback

2017年11月11日 13:46 学习笔记 暂无评论 共691字 (阅读2,799 views次)

【注意:此文章为博主原创文章!转载需注意,请带原文链接,至少也要是txt格式!】

php 5.x 版本preg_replace 源代码:

1
2
3
4
5
6
7
/* replace special blocks by "{php}" */
$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);

转换为php 7.x 版本preg_replace_callback

1
2
3
4
5
6
7
/* replace special blocks by "{php}" */
$source_content = preg_replace_callback($search, create_function ('$matches', "return '"
                                       . $this->_quote_replace($this->left_delimiter) . 'php'
                                       . "' . str_repeat(\"\n\", substr_count('\$matches[1]', \"\n\")) .'"
                                       . $this->_quote_replace($this->right_delimiter)
                                       . "';")
                                       , $source_content);

最后说一句 smarty 更新了。
https://github.com/simpleinvoices/simpleinvoices/tree/master/library/smarty

布施恩德可便相知重

微信扫一扫打赏

支付宝扫一扫打赏

×

给我留言