note 39853 added to function.ereg-replace

From: Date: Fri, 13 Feb 2004 01:28:32 +0000
Subject: note 39853 added to function.ereg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-65072@lists.php.net to get a copy of this message
Another proposal for those who are looking for some nice "replace URLs with links" script. Actually I found bugs in all the suggestions above. My script replaces URLs and e-mail addresses no matter how many of them there are in the string. The URL must start with "http: // (ftp, https)", "http: // www" or just "www". function url_to_link($str) { global $str; $str = eregi_replace ("[[:alpha:]]+://www", "www",$str); $str = ereg_replace ("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/](\.[a-z0-9-]{2,4})+", "<a href=\\0 target=_blank>\\0</a>", $str); $str = ereg_replace ("www.[^<>[:space:]]+[[:alnum:]/](\.[a-z0-9-]{2,4})+", "<a href=http://\\0 target=_blank>\\0</a>", $str); $str = ereg_replace ("[[:alpha:]]+@[^<>[:space:]]+[[:alnum:]/](\.[a-z0-9-]{2,4})+", "<a href=mailto:\\0 target=_blank>\\0</a>", $str); } ---- Manual Page -- http://www.php.net/manual/en/function.ereg-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39853 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39853&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39853&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#65072) next »