gpt4 book ai didi

php -/e 修饰符已弃用,从 php5.2.6 迁移后改用 preg_replace_callback

转载 作者:行者123 更新时间:2023-12-05 07:48:32 26 4
gpt4 key购买 nike

我最近从 php5.2.6 迁移到 php5.6.22,现在我收到这个错误。

Unkwown error. 8192: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead

似乎 preg_replace 在 php5.6++ 中被弃用

http://php.net/manual/en/migration55.deprecated.php

这是我使用 `preg_replace 函数的整个函数:

function mb_unserialize( $serial_str ) {
$out = preg_replace( '!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $serial_str );
return unserialize( $out );
}

有人可以解释一下我应该如何使用这种模式实现 preg_replace_callback 函数吗? preg_replace_callback 在这种情况下如何工作?

谢谢

最佳答案

正式回答:

function mb_unserialize( string $serial_str ):string {
return unserialize( preg_replace_callback(
'/s:(?:\d+):"(.*?)";/s', // -- the first pair of parentheses is not used.
function( array $matches ): string { // -- this is the callback.
return 's:' . strlen( $matches[1] ) . ':"' . $matches[1] . '";';
},
$serial_str
));
}

关于php -/e 修饰符已弃用,从 php5.2.6 迁移后改用 preg_replace_callback,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38432305/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com