0

I need a little help. Because In preg_replace /e is deprecated, I have to convert all my preg_replace to preg_replace_callback...

Old Code

$status = preg_replace("/((http:\/\/|https:\/\/)[^ )
        ]+)/e", "'<a href=\"$1\" title=\"$1\" >'. ((strlen('$1')>=250 ? substr('$1',0,250).'...':'$1')).'</a>'", $status);

And this is the one I have to change it to preg_replace_callback

 $status = preg_replace_callback("/((http:\/\/|https:\/\/)[^ )d]+)/",
    function($m) {
        return '<a href=\"$m\" title=\"$m\" >'. ((strlen('$m[0]')>=250 ? substr('$m[0]',0,250).'...':'$m[0]')).'</a>';
    },
    $status);

But it is not working. I hope anyone will help me out

  • `'$m[0]'` is a 5 character string. And `$m[0]` is a value of `0` key of `$m` array. – u_mulder Sep 03 '16 at 13:30
  • Remove the quotes around the variable. – Charlotte Dunois Sep 03 '16 at 13:31
  • There are multiple things wrong here. First do `print_r($m);` inside the callback, just for you to see what you actually have. Then you see that `$m` is an array and you can't just use it inside a string as you want it to. You need to access the index you need. Also see the difference between single and double quotes: http://stackoverflow.com/q/3446216/3933332 variables inside single quotes are not parsed. Just for readability you probably just want to concatenate your variables. – Rizier123 Sep 03 '16 at 13:33

0 Answers0