linkcreate créer un lien automatiquement en affichant un texte contenant un href…
source: http://www.commentcamarche.net/contents/php/phpreg.php3
Le code suivant (utilisation avancée des expressions régulières) remplace un URL par un hypertexte HTML (il remplace toute suite de caractères de ponctuations et alphanumériques commençant par http://, ou ftp: par le même texte (sans le http:) entre balises HTML hypertexte…) :
$Texte = "Bienvenue sur http://www.commentcamarche.net cher ami"; $Texte = ereg_replace("(http://)(([[:punct:]]|[[:alnum:]])*)", "<a href=\"\\0\">\\2</a>",$Texte);
voir aussi: http://www.keliglia.com/categorie/php/
$texte = preg_replace("/(http|https|ftp|mailto)(:)(\/\/){0,}(\S*)/i", "<a href=\"$1$2$3$4\" title=\"$1$2$3$4\">$1$2$3$4</a>", $texte);
et http://ch2.php.net/eregi_replace
If you have plain text e-mails and links but need to make them real links <? function replaceLinks($text) { // convert support@pogoda.in into // <a href="mailto:support@pogoda.in"> // support@pogoda.in</a> $text = ereg_replace('[-a-z0-9!#$%&\'*+/=?^_`{|}~]+@([.]?[a-zA-Z0-9_/-])*', '<a href="mailto:\\0">\\0</a>',$text); // convert http://www.pogoda.in/new_york/eng/ into // <a href="http://pogoda.in/new_york/eng/"> // pogoda.in/new_york/eng/</a> $text = ereg_replace('[a-zA-Z]+://(([.]?[a-zA-Z0-9_/-])*)', '<a href="\\0">\\1</a>',$text); // convert www.pogoda.in/new_york/eng/ into // <a href="http://www.pogoda.in/new_york/eng/"> // www.pogoda.in/new_york/eng/</a> $text = ereg_replace('(^| )(www([-]*[.]?[a-zA-Z0-9_/-?&%])*)', ' <a href="http://\\2">\\2</a>',$text); return $text; } ?>