2013-02-25 79 views
0

http://www.internoetics.com/2010/01/12/simple-whois-php-script/ PHP域名註冊腳本的preg_replace,我需要配置它最新的PHP版本,我需要轉換額日格和eregi到的preg_match和的preg_replace轉換eregi到的preg_match和ereg_replace使用

if ((!eregi('^[a-zA-Z0-9-]+\.([a-zA-Z]{2,4})$', $domain)) && (!eregi('^[a-zA-Z0-9-]+\.([a-zA-Z]{2,4})+\.([a-zA-Z]{2,4})$', $domain))) $arrErrors['domi'] = 'Domain name appears to be invalid.'; 

function makeClickableLinks($text) 
{ 
     $text = html_entity_decode($text); 
     $text = " ".$text; 
     $text = eregi_replace('(((f|ht){1}tp://)[[email protected]:%_\+.~#?&//=]+)', 
       '<a href="\\1" target=_blank>\\1</a>', $text); 
     $text = eregi_replace('(((f|ht){1}tps://)[[email protected]:%_\+.~#?&//=]+)', 
       '<a href="\\1" target=_blank>\\1</a>', $text); 
     $text = eregi_replace('([[:space:]()[{}])(www.[[email protected]:%_\+.~#?&//=]+)', 
     '\\1<a href="http://\\2" target=_blank>\\2</a>', $text); 
     $text = eregi_replace('([_\.0-9a-z-][email protected]([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', 
     '<a href="mailto:\\1" target=_blank>\\1</a>', $text); 
     return $text; 
} 

感謝

回答

0

對於preg_ *函數,您只需在模式的開始和結尾添加分隔符,例如/#或其他。

寫這

if ((!preg_match('/^[a-z\d-]+\.([a-z]{2,4})$/i', $domain)) && (!preg_match('/^[a-z\d-]+\.([a-z]{2,4})+\.([a-z]{2,4})$/', $domain))) 
    echo $arrErrors['domi'] = 'Domain name appears to be invalid.'; 

function makeClickableLinks($text) 
{ 
     $text = html_entity_decode($text); 
     $text = " ".$text; 
     $text = preg_replace('#(((f|ht){1}tp://)[-a-z\[email protected]:%_\+.~\#?&//=]+)#', 
       '<a href="\\1" target=_blank>\\1</a>', $text); 
     $text = preg_replace('#(((f|ht){1}tps://)[-a-z\[email protected]:%_\+.~\#?&//=]+)#', 
       '<a href="\\1" target=_blank>\\1</a>', $text); 
     $text = preg_replace('#([[:space:]()[{}])(www.[-a-z\[email protected]:%_\+.~\#?&//=]+)#', 
     '\\1<a href="http://\\2" target=_blank>\\2</a>', $text); 
     $text = preg_replace('#([_\.\da-z-][email protected]([\da-z][\da-z-]+\.)+[a-z]{2,3})#', 
     '<a href="mailto:\\1" target=_blank>\\1</a>', $text); 
     return $text; 
} 
+0

可以顯示如何做到這一點?因爲我不熟悉reg表達式..:/ – Dance 2013-02-25 08:29:47

+0

@Dance我已經更新了我的答案 – Winston 2013-02-25 08:56:27

+0

謝謝,像一個魅力一樣工作! – Dance 2013-02-25 09:01:47