警告:preg_replace_callback():需要参数 2 才能成为有效的回调
Warning: preg_replace_callback(): Requires argument 2, to be a valid callback
我正在使用 wordpress 插件 Ultimate Membership Pro。我的代码中有一个小警告。我不知道是什么问题。
我试过查看 php 手册,也对这个主题进行了研究,但无法解决。任何人都知道如何解决它?只需要一个提示。
Php代码:
原码:
if (!empty($data->history)){
//print the history
$dat = preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('').':\"\";'", $data->history);
$dat = unserialize($dat);
if (isset($dat) && is_array($dat)){
foreach ($dat as $k=>$transaction_history_arr){
if (is_string($transaction_history_arr)){
//is json
$json = stripslashes($transaction_history_arr);
if ($k){
echo '<h4>' . date('Y-m-d H:i:s', $k) .'</h4>';
}
$arr = (array)json_decode($json, true);
foreach ($arr as $key=>$value){
echo $key.': '.$value.'<br/>';
}
} else {
//is an array
if ($k>0){
echo '<h4>' . date('Y-m-d H:i:s', $k) .'</h4>';
}
foreach ($transaction_history_arr as $key=>$value){
echo $key.' : '.$value.'<br/>';
}
}
}
}
}
错误:
Warning: preg_replace(): The /e modifier is no longer supported, use
preg_replace_callback instead in
/var/www/html/stock-market/wp-content/plugins/indeed-membership-pro/admin/includes/tabs/list_payments.php
on line 44
更新为preg_replace_callback:
if (!empty($data->history)){
//print the history
print_r($data->history);
$dat = preg_replace_callback('!s:(\d+):"(.*?)";!e', "'s:'.strlen('').':\"\";'", $data->history);
$dat = unserialize($dat);
更新后的输出是这样的:
Warning: preg_replace_callback(): Requires argument 2,
''s:'.strlen('').':"";'', to be a valid callback in
/var/www/html/stock-market/wp-content/plugins/indeed-membership-pro/admin/includes/tabs/list_payments.php
on line 44 2017-06-17 08:44:49
ihc_payment_type : paypal
details : ss
uid : 1
level : 2
order_id : 21
amount : 100.00
currency : USD
txn_id : 1_21_1497689089
message : success
我的数组是 $data->history :
a:1:{i:1497689089;a:9:{s:16:"ihc_payment_type";s:6:"paypal";s:7:"details";s:2:"ss";s:3:"uid";s:1:"1";s:5:"level";s:1:"2";s:8:"order_id";s:2:"21";s:6:"amount";s:6:"100.00";s:8:"currency";s:3:"USD";s:6:"txn_id";s:15:"1_21_1497689089";s:7:"message";s:7:"success";}}
警告:
Warning: preg_replace_callback(): Requires argument 2, ''s:'.strlen('').':"";'', to be a valid callback in /var/www/html/stock-market/wp-content/plugins/indeed-membership-pro/admin/includes/tabs/list_payments.php on line 47
如果我对你正在尝试做的事情的看法是正确的,这可能就是你要找的:
$text = 'a:1:{i:1497689089;a:9:{s:16:"ihc_payment_type";s:6:"paypal";s:7:"details";s:2:"ss";s:3:"uid";s:1:"1";s:5:"level";s:1:"2";s:8:"order_id";s:2:"21";s:6:"amount";s:6:"100.00";s:8:"currency";s:3:"USD";s:6:"txn_id";s:15:"1_21_1497689089";s:7:"message";s:7:"success";}}';
$dat = preg_replace_callback('!s:(\d+):"(.*?)";!',
function ($match) {
return 's:'.strlen($match[2]).':"'.$match[2].'";';
},
$text);
请注意,我从搜索模式中删除了 e
修饰符,然后传入一个函数作为第二个参数。此函数采用匹配项和 returns 您想要的替换项。
(另请注意,对于给定的输入,此替换不会改变任何内容。)
我正在使用 wordpress 插件 Ultimate Membership Pro。我的代码中有一个小警告。我不知道是什么问题。
我试过查看 php 手册,也对这个主题进行了研究,但无法解决。任何人都知道如何解决它?只需要一个提示。
Php代码:
原码:
if (!empty($data->history)){
//print the history
$dat = preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('').':\"\";'", $data->history);
$dat = unserialize($dat);
if (isset($dat) && is_array($dat)){
foreach ($dat as $k=>$transaction_history_arr){
if (is_string($transaction_history_arr)){
//is json
$json = stripslashes($transaction_history_arr);
if ($k){
echo '<h4>' . date('Y-m-d H:i:s', $k) .'</h4>';
}
$arr = (array)json_decode($json, true);
foreach ($arr as $key=>$value){
echo $key.': '.$value.'<br/>';
}
} else {
//is an array
if ($k>0){
echo '<h4>' . date('Y-m-d H:i:s', $k) .'</h4>';
}
foreach ($transaction_history_arr as $key=>$value){
echo $key.' : '.$value.'<br/>';
}
}
}
}
}
错误:
Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /var/www/html/stock-market/wp-content/plugins/indeed-membership-pro/admin/includes/tabs/list_payments.php on line 44
更新为preg_replace_callback:
if (!empty($data->history)){
//print the history
print_r($data->history);
$dat = preg_replace_callback('!s:(\d+):"(.*?)";!e', "'s:'.strlen('').':\"\";'", $data->history);
$dat = unserialize($dat);
更新后的输出是这样的:
Warning: preg_replace_callback(): Requires argument 2, ''s:'.strlen('').':"";'', to be a valid callback in /var/www/html/stock-market/wp-content/plugins/indeed-membership-pro/admin/includes/tabs/list_payments.php on line 44 2017-06-17 08:44:49
ihc_payment_type : paypal
details : ss
uid : 1
level : 2
order_id : 21
amount : 100.00
currency : USD
txn_id : 1_21_1497689089
message : success
我的数组是 $data->history :
a:1:{i:1497689089;a:9:{s:16:"ihc_payment_type";s:6:"paypal";s:7:"details";s:2:"ss";s:3:"uid";s:1:"1";s:5:"level";s:1:"2";s:8:"order_id";s:2:"21";s:6:"amount";s:6:"100.00";s:8:"currency";s:3:"USD";s:6:"txn_id";s:15:"1_21_1497689089";s:7:"message";s:7:"success";}}
警告:
Warning: preg_replace_callback(): Requires argument 2, ''s:'.strlen('').':"";'', to be a valid callback in /var/www/html/stock-market/wp-content/plugins/indeed-membership-pro/admin/includes/tabs/list_payments.php on line 47
如果我对你正在尝试做的事情的看法是正确的,这可能就是你要找的:
$text = 'a:1:{i:1497689089;a:9:{s:16:"ihc_payment_type";s:6:"paypal";s:7:"details";s:2:"ss";s:3:"uid";s:1:"1";s:5:"level";s:1:"2";s:8:"order_id";s:2:"21";s:6:"amount";s:6:"100.00";s:8:"currency";s:3:"USD";s:6:"txn_id";s:15:"1_21_1497689089";s:7:"message";s:7:"success";}}';
$dat = preg_replace_callback('!s:(\d+):"(.*?)";!',
function ($match) {
return 's:'.strlen($match[2]).':"'.$match[2].'";';
},
$text);
请注意,我从搜索模式中删除了 e
修饰符,然后传入一个函数作为第二个参数。此函数采用匹配项和 returns 您想要的替换项。
(另请注意,对于给定的输入,此替换不会改变任何内容。)