scrivo questa funzione. Sostituisce tutti i collegamenti in una stringa. I link possono essere nei seguenti formati:
Il secondo argomento è l'obiettivo per il link (' _blank ',' _top '... può essere impostato su false). Speranza che aiuta ...
public static function makeLinks($str, $target='_blank')
{
if ($target)
{
$target = ' target="'.$target.'"';
}
else
{
$target = '';
}
// find and replace link
$str = preg_replace('@((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)@', '<a href="$1" '.$target.'>$1</a>', $str);
// add "http://" if not set
$str = preg_replace('/<a\s[^>]*href\s*=\s*"((?!https?:\/\/)[^"]*)"[^>]*>/i', '<a href="http://$1" '.$target.'>', $str);
return $str;
}
fonte
2014-10-28 09:53:11
Duplicate: See # 1.038.284 - http://stackoverflow.com/questions/1038284/php-parse-links-emails – Sampson