2010-01-18 4 views
15

더 이상 사용되지 않는 eregi_replace 함수에 대한 좋은 대안을 아는 사람이 있습니까?deprecated PHP 함수의 대안 : eregi_replace

나는이 스니 플릿에 필요한 :

$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); 

감사합니다!

답변

20

preg_replace이다 당신은 preg_XXX`에 대한 구분 문자를 사용할 필요가

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

$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); 
+4

()'. OP가'eregi' (대소 문자 구별 없음) 대신에'i' 플래그 ('preg_replace ('/(...)/i', ...)'를 추가해야합니다. –

+0

사실, 나쁜 복사/붙여 넣기, 미안 해요, 내 대답에 추가 –