1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| <?php
$str = "Dans cette phrase, j'ai l'url www.free.fr que je veux transformer";
$valide = '[A-Za-z0-9$|.+!*\(\),;/?:@&~=_%-]+';
$reg = "{
#protocoles suivi de :// falcutatif
(
(?: ftp|http|https|gopher|mailto|pop|smtp|news|nntp|telnet|wais|file|imap|
prospero|peercast|ed2k|irc|aim|mime|ftam|pnm|rtsp|ldap
)
://)?
# ici je fais plus simple
( $valide \. )+
$valide
}x";
preg_match($reg, $str, $m);
print_r($m);
echo preg_replace($reg, '<a href="$0">url</a>', $str); |