Closed (fixed)
Project:
Freelinking
Version:
master
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
9 May 2005 at 17:20 UTC
Updated:
29 May 2005 at 16:15 UTC
Only links with http are supported. Https is not.
As a quick change you can do this:
Change
if (substr($freelink,0,7) == 'http://') {
$replacement = '<a href="' . $freelink . '">' . $phrase . '</a>';
}
to
if ( (substr($freelink,0,7) == 'http://') || (substr($freelink,0,8) == 'https://') ) {
$replacement = '<a href="' . $freelink . '">' . $phrase . '</a>';
}
Comments
Comment #1
eafarris commentedEven better would be a more generic solution to handle any valid url, like ftp:// and mailto: schemes in addition to http[s]:// .
Comment #2
eafarris commentedCommitted version 1.6 to HEAD, supporting http, mailto, https, and ftp uri schemes. Please verify and close.
Comment #3
rar commentedyour code is ok
> if (preg_match('/^(http|mailto|https|ftp):/', $freelink)) {
How about
if (preg_match('/^(\w+):\/\//',$freelink)
which avoids
1) hardcoding in protocols
2) having 5N operations for N matches.
3) matching non link text like "http: The definition of http is...."
Note: the above code is untested.
Comment #4
eafarris commentedI like this, but there are exceptions to "word colon slash slash": the "mailto:" protocol does not require (and, in fact, i've never seen) the double slashes. and "file:" requires (i think) three slashes. It can be easy, good, or correct: pick two. I think the current code is "easy, and "good," so I'll leave it how it is for now (that is, not "correct"), and wait for people to complain about not having "feed://" or "rtsp://" or "somethingelse:" protocol handlers.
A quick searching on google and safari.oreilly.com shows some very intricate regexps to attempt to handle URI schemes. Bleh. At this time, I don't want a complex regexp there, more correct though it may be. If only there was an is_url() function! :)
Comment #5
(not verified) commented