mvc01,妳好:
妳所提出的問題使用正則即可解決,具體如下:
自動添加"http://"頭的PHP函數代碼:
<?phpif?(!preg_match("/^(http|ftp):/",?$_POST['url'])){
$_POST['url']?=?'
$_POST['url'];
}
>PHP將網址字符串轉換成超級鏈接,可將URL和E-mail 地址字符串轉換為可點擊的超級鏈接:
<?phpfunction?makeClickableLinks($text)?{
$text?=?eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)', '<a?href="\1">\1</a>',?$text); $text?=?eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&//=]+)', '\1<a?href=",?$text);
$text?=?eregi_replace('([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})', '<a?href="mailto:\1">\1</a>',?$text);return?$text;
}
>