我正在使用wordpress插件Ultimate Membership Pro。我的代碼中有一個小警告。我無法弄清楚問題是什麼。警告:preg_replace_callback():需要參數2,才能成爲有效的回調
我試着檢查PHP手冊,也做這個主題的研究,但無法解決它。任何人有一個想法如何解決它?只需要一個提示。
PHP代碼:
原始代碼:
if (!empty($data->history)){
//print the history
$dat = preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'", $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('$2').':\"$2\";'", $data->history);
$dat = unserialize($dat);
對於更新的輸出是這樣的:
Warning: preg_replace_callback(): Requires argument 2, ''s:'.strlen('$2').':"$2";'', 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
我的數組是$數據 - >歷史:
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('$2').':"$2";'', 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
錯誤消息非常簡單。我想你只需要'preg_replace'。 – smarx
@smarx我把它'preg_replace'改爲'preg_replace_callback',並給我警告我的PHP不支持'preg_replace' php 7.x –
根據http://php.net/manual/en/function.preg-replace .php,應該在PHP 7中支持'preg_replace'。什麼是確切的錯誤信息? – smarx