Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative for deprecated PHP function: eregi_replace [duplicate]

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!

like image 805
Juri Avatar asked Jan 18 '10 09:01

Juri


2 Answers

preg_replace

https://php.net/preg-replace

$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);
like image 75
Guillaume Flandre Avatar answered Nov 18 '22 17:11

Guillaume Flandre


preg_replace

like image 41
leepowers Avatar answered Nov 18 '22 17:11

leepowers