0

Possible Duplicate:
Deprecated: Function eregi_replace()

I have an error that reads:

Deprecated: Function ereg_replace() is deprecated in /home/socia125/public_html/wi_class_files/autoMakeLinks.php on line 26

My code is here. Any help is appreciated.

<?php

    class autoActiveLink {

    function makeActiveLink($originalString){

        $newString = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a 

        href=\"\\0\" target=\"_blank\">\\0</a>", $originalString);
        return $newString;
    }

}
?>
Community
  • 1
  • 1
Rocko Jedi
  • 3
  • 1
  • 3

3 Answers3

0

ereg functions are deprecated as of PHP 5.3.0. Use preg instead.

class autoActiveLink {
    function makeActiveLink($originalString) {

        $newString = preg_replace("|[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]|",
                                  "<a href=\"\\0\" target=\"_blank\">\\0</a>",
                                  $originalString
        );
        return $newString;
    }
}

Note that on preg functions, you need a delimiter for your Regex. Refer to the manual for additional details.

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
0

Use preg_replace instead.

For the most part, the only real difference is that you have to have delimiters around the regex. I usually use ( at the start and ) at the end, but you can use any two matching symbols. The advantage of () is that you never have to escape anything just for the purpose of avoiding conflict with the delimiter.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
0

Using preg_replace:

$newString = preg_replace("#[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]#","<a href=\"\\0\" target=\"_blank\">\\0</a>", $originalString);
flowfree
  • 16,356
  • 12
  • 52
  • 76