Bonjour à tous,
Voilà, j'ai une fonction avec RegEx pour rendre des url ou adresse mail cliquable à l'affichage.
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 function url_cliquable($string) { // le texte ou l on va rendre les email et les urls cliquables $in = array( '`((?:https?|ftp)://\\S+)(\\s|\\z)`', '`([[:alnum:]]([-_.]?[[:alnum:]])*@[[:alnum:]]([-_.]?[[:alnum:]])*\.([a-z]{2,4}))`', '`((?<!//)(www\.)\S+)(\s|\z)`' ); $out = array( '<a href="$1" target="_blank">$1</a>$2', '<a href="mailto:$1">$1</a>', '<a href="http://$1" target="_blank">$1</a>', ); return preg_replace($in, $out, $string); }
Cela marche impeccable, sauf sur une url du genre http://www.site.fr/1/www.site.fr/dossier/index.php
Forcément il me détecte une url imbriqué, et me crée un deuxième lien html. A l'affichage, forcément ça ne passe pas
J'ai jamais été doué en regex, si une âme charitable pouvait m'aider ...
Merci !
Partager