Alternative for deprecated PHP function: eregi_replace

Do anyone know a good alternative for the deprecated eregi_replace function?

I need it for this sniplet:

$pattern = "([a-z0-9][_a-z0-9.-][email protected]([0-9a-z][_0-9a-z-]+\.)+[a-z]{2,6})";
$replace = "<a href=\"mailto:\\1\">\\1</a>";
$text = eregi_replace($pattern, $replace, $text);

Thanks!

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

preg_replace

https://php.net/preg-replace

$pattern = "/([a-z0-9][_a-z0-9.-][email protected]([0-9a-z][_0-9a-z-]+\.)+[a-z]{2,6})/i";
$replace = "<a href=\"mailto:\\1\">\\1</a>";
$text = preg_replace($pattern, $replace, $text);

Solution 2

preg_replace

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply