Warning: preg_replace_callback(): Requires argument 2, to be a valid callback

admin

Administrator
Staff member
I am using wordpress plugin Ultimate Membership Pro. I have a small warning in my code. I can't figure out what the issue is.

I tried checking php manual and also doing research on this topic but can't solve it. Anyone have an idea how to solve it? Just need a hint.

<strong>Php Code:</strong>

Original Code:

Code:
if (!empty($data-&gt;history)){
        //print the history
        $dat = preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'", $data-&gt;history);
        $dat = unserialize($dat);       
        if (isset($dat) &amp;&amp; is_array($dat)){
            foreach ($dat as $k=&gt;$transaction_history_arr){
                if (is_string($transaction_history_arr)){
                    //is json
                    $json = stripslashes($transaction_history_arr);
                    if ($k){
                        echo '&lt;h4&gt;' . date('Y-m-d H:i:s', $k) .'&lt;/h4&gt;';
                    }
                    $arr = (array)json_decode($json, true);
                    foreach ($arr as $key=&gt;$value){
                        echo $key.': '.$value.'&lt;br/&gt;';
                    }
                } else {    
                    //is an array
                    if ($k&gt;0){ 
                        echo '&lt;h4&gt;' . date('Y-m-d H:i:s', $k) .'&lt;/h4&gt;';
                    }
                    foreach ($transaction_history_arr as $key=&gt;$value){
                        echo $key.' : '.$value.'&lt;br/&gt;';
                    }
                }
            }
        }
    }

<strong>Error:</strong>

<blockquote>
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
</blockquote>

<strong>Updated with preg_replace_callback:</strong>

Code:
if (!empty($data-&gt;history)){
        //print the history
        print_r($data-&gt;history);
        $dat = preg_replace_callback('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'", $data-&gt;history);
        $dat = unserialize($dat);

For updated Output something like this:

<blockquote>
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
</blockquote>

Code:
  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

my array is <strong>$data->history</strong> :

<blockquote>
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";}}
</blockquote>

<strong>Warning:</strong>

Code:
 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