0

i saw this code some where and decided to use it. it works fine but i was told preg_replace has been deprecated that i should replace it with preg_replace_callback but once i did that it started showing me errors that my parameter 2 should be a call back, have tried to create a call back but got another error

<?php 
function checkPost($result){
     array(
       "stripslashes((strlen('\\2')>0?'\\1<a href=\"\\2\">\\2</a>\\3':'\\0'))",
       '<a\\1',
       '<a\\1 target="_blank">',
       "stripslashes((strlen('\\2')>0?'\\1<a href=\"http://\\2\">\\2</a>\\3':'\\0'))",
       "stripslashes((strlen('\\2')>0?'<a href=\"mailto:\\0\">\\0</a>':'\\0'))"
       );
    return $result;
    }
    
function make_links_blank($post)
{
  return  preg_replace_callback(
     array(
       '/(?(?=<a[^>]*>.+<\/a>)
             (?:<a[^>]*>.+<\/a>)
             |
             ([^="\']?)((?:https?|ftp|bf2|):\/\/[^<> \n\r]+)
         )/iex',
       '/<a([^>]*)target="?[^"\']+"?/i',
       '/<a([^>]+)>/i',
       '/(^|\s)(www.[^<> \n\r]+)/iex',
       '/(([_A-Za-z0-9-]+)(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-]+)
       (\\.[A-Za-z0-9-]+)*)/iex'
       ),
    "checkPost"
    ,
       $post
   );
}
echo make_links_blank($post);

?>
caleb
  • 3
  • 5
  • `preg_replace` itself hasn't been deprecated just the `e` modifier. – Daan Nov 23 '15 at 12:00
  • but it is showing me errors here that it has been deprecated, so how do i deal with the e modifier – caleb Nov 23 '15 at 12:55
  • @caleb Use [`preg_replace_callback`](http://php.net/manual/en/function.preg-replace-callback.php) with an anonymous function but *only* on the regexes that use the `e` modifier. – h2ooooooo Nov 23 '15 at 13:33

0 Answers0