PHP preg_replace替代 [英] PHP preg_replace alternative

查看:100
本文介绍了PHP preg_replace替代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于弃用,我们当前在网站上收到一条preg_replace错误消息。

We're currently getting a preg_replace error message on our site due to deprecation.

我们的代码如下:

$out = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $data);

关于如何用不推荐使用的代码替换的任何建议?

Any suggestions on how this can be replaced with non-deprecated code?

推荐答案

preg _ 。它只是 / e (从PHP 5.5开始):

preg_ is not deprecated. It is just /e (as of PHP 5.5):


/ e不推荐使用修饰符。请使用 preg_replace_callback()
请参见 PREG_REPLACE_EVAL 文档以获取有关安全风险的其他信息

The /e modifier is deprecated. Use preg_replace_callback() instead. See the PREG_REPLACE_EVAL documentation for additional information about security risks.

preg_replace_callback () preg_replace()几乎相同,不同之处在于它使用回调而不是替换,因此更新代码应是一项快速的功课。

and as preg_replace_callback() is almost identical to preg_replace() with exception that it uses callback instead of replacement, update of your code should be quick homework.

这篇关于PHP preg_replace替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆