views:

501

answers:

2

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.-]+@([0-9a-z][_0-9a-z-]+\.)+[a-z]{2,6})";
$replace = "<a href=\"mailto:\\1\">\\1</a>";
$text = eregi_replace($pattern, $replace, $text);

Thanks!

+3  A: 

preg_replace

http://php.net/manual/fr/function.preg-replace.php

$pattern = "/([a-z0-9][_a-z0-9.-]+@([0-9a-z][_0-9a-z-]+\.)+[a-z]{2,6})/i";
$replace = "<a href=\"mailto:\\1\">\\1</a>";
$text = preg_replace($pattern, $replace, $text);
Guillaume Flandre
You need to use delimiter characters for `preg_XXX()`. Since the OP is looking for an alternative to `eregi` (case-insensitive), you should also add the `i` flag (`preg_replace('/(...)/i', ...)`).
Ferdinand Beyer
True, bad copy/paste, sorry about that, I added it to my answer
Guillaume Flandre
+1  A: 

preg_replace

pygorex1