oops
authorx2001corpet <x2001corpet@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 21 Oct 2006 13:06:41 +0000 (13:06 +0000)
committerx2001corpet <x2001corpet@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 21 Oct 2006 13:06:41 +0000 (13:06 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@997 839d8a87-29fc-0310-9880-83ba4fa771e5

include/url_catcher.inc.php [new file with mode: 0644]

diff --git a/include/url_catcher.inc.php b/include/url_catcher.inc.php
new file mode 100644 (file)
index 0000000..b1dd3f8
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+
+// renvoie un texte html à partir d'un texte classique
+// en remplacant les url par des liens (éventuellement les mails)
+function url_catcher($texte, $mails = true) {
+       $patterns = array();
+       $replacement = array();
+       
+       // url commencant par http, https ou ftp
+       $patterns[] = '/((?:https?|ftp):\/\/(?:\.*,*[a-z@0-9~%$£µ&i#\-+=_\/\?])*)/i';
+       $replacement[] = '<a href="\\0">\\0</a>';
+       
+       // url commencant par www.
+       $patterns[] = '/(\s|^)www\.((?:\.*,*[a-z@0-9~%$£µ&i#\-+=_\/\?])*)/i';
+       $replacement[] = '\\1<a href="http://www.\\2">www.\\2</a>';
+       
+       if ($mails) {
+        $patterns[] = '/(?:mailto:)?([a-z0-9.\-+_]+@([\-.+_]?[a-z0-9])+)/i';
+        $replacement[] = '<a href="mailto:\\0">\\0</a>';
+       }
+       
+    return preg_replace($patterns, $replacement, $texte);
+}
+?>