<?php
function autolink($text)
{
$sym = "(?:[,;.:"'!?()[]{}-]|&|"|'|&[gl]t;)*";
$beg = "((?:^|>|s)$sym?)";
$end = "($sym(?:s|<|$))";
return preg_replace(
array(
"/$beg((?:https?|ftp|news|telnet|ed2k):[S]+)$end/Ui",
"/$beg(www.[S]+)$end/Ui",
"/$beg(ftp.[S]+)$end/Ui",
"/$beg([^s/]+@[a-z0-9.-]+.[a-z]{2,6})$end/Ui"),
array(
"\1<a href="/\2" target='_blank'>\2</a>\3",
"\1<a href="http://\2" target='_blank'>\2</a>\3",
"\1<a href="ftp://\2" target='_blank'>\2</a>\3",
"\1<a href="mailto:\2">\2</a>\3"), $text);
}
$text = "to jest mój link: www.bastek.zwa.pl";
//wywołujemy funkcję i wyświetlamy tekst
$text = autolink($text);
echo $text." już dynamiczny";
?>