- 28 Eki 2008
- 1,536
- 1
Metindeki web adreslerini otomatik link yapma
function txt2link($text) {
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '<a href="\\1" target="_blank">\\1</a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1<a href="http://\\2" target="_blank">\\2</a>', $text);
$text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', '<a href="mailto:\\1">\\1</a>', $text);
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
if(preg_match_all("/$regexp/siU", $text, $matches)) {
# $matches[2] = array of link addresses
# $matches[3] = array of link text - including HTML code
foreach ($matches[3] as $key=>$val) {
if ($val[50]) {
$text = str_replace(">" . $val . "<", ">" . substr($val,0,50) . "...<", $text);
}
}
}
return $text;
}
function txt2link($text) {
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '<a href="\\1" target="_blank">\\1</a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1<a href="http://\\2" target="_blank">\\2</a>', $text);
$text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', '<a href="mailto:\\1">\\1</a>', $text);
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
if(preg_match_all("/$regexp/siU", $text, $matches)) {
# $matches[2] = array of link addresses
# $matches[3] = array of link text - including HTML code
foreach ($matches[3] as $key=>$val) {
if ($val[50]) {
$text = str_replace(">" . $val . "<", ">" . substr($val,0,50) . "...<", $text);
}
}
}
return $text;
}