note 12217 deleted from ref.strings by maxim

From: Date: Tue, 12 Nov 2002 16:19:07 +0000
Subject: note 12217 deleted from ref.strings by maxim
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-39394@lists.php.net to get a copy of this message
Here is a very slight fix to this function to make URLs in strings clickable. The change allows URLs that have a dash character "-" to not stop the href tag just before the "-". The change un-literals the "-" in the eregi function since the eregi function appears to not want this when you are trying to match an actual "-". Seems that different languages have different requirements about what should be literal. This: eregi("[a-z0-9\.\:\?\/\~\-\_\&\=\%\+\'\"]", $string[$n]) becomes this: eregi("[a-z0-9\.\:\?\/\~\_\&\=\%\+\'\"-]", $string[$n]) // Makes all words starting with http:// clickable function urls_clickable($string) { for($n=0; $n < strlen($string); $n++) { if(strtolower($string[$n]) == 'h') { if(!strcmp("http://", strtolower($string[$n]) . strtolower($string[$n+1]) . strtolower($string[$n+2]) . strtolower($string[$n+3]) . $string[$n+4] . $string[$n+5] . $string[$n+6])) { $startpos = $n; while($n < strlen($string) && eregi("[a-z0-9\.\:\?\/\~\_\&\=\%\+\'\"-]", $string[$n])) $n++; if(!eregi("[a-z0-9]", $string[$n-1])) $n--; $link = substr($string, $startpos, ($n-$startpos)); $link = $link; $string_tmp = $string; $string = substr($string_tmp, 0, $startpos); $string .= "<a href=\"$link\">$link</a>"; $string .= substr($string_tmp, $n, strlen($string_tmp)); $n = $n + 15; } } } return $string; }

« previous php.notes (#39394) next »