/    Sign up×
Community /Pin to ProfileBookmark

find the "http://" bit in a url string

hi, simple question (me thinks)

lets say i have a url form box. well, obv some people are going to miss off the http:// bit, how can i add this so if [url]www.webdeveloper.com[/url] was the string it would go, [url]http://www.webdeveloper.com[/url].

however, if [url]http://www.webdeveloper.com[/url] was entered it would leave it as it is…

thanks

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@pcthugAug 27.2006 — [code=php]
// where $url is the given URL
if(substr($url, 0, 7) != 'http://') {
$url = "http://$url";
}[/code]
You may however want to add support for other protocols, i.e. ftp, https, etc.
Copy linkTweet thisAlerts:
@deep-woodauthorAug 27.2006 — [code=php]
// where $url is the given URL
if(substr($url, 0, 7) != 'http://') {
$url = "http://$url";
}[/code]
You may however want to add support for other protocols, i.e. ftp, https, etc.[/QUOTE]

ahh thankyou! ?
Copy linkTweet thisAlerts:
@Ness_du_FratAug 27.2006 — Hey, thanks as well !!! I was actually going to post exactly the same question when I found this thread.

Works fine ?
Copy linkTweet thisAlerts:
@pcthugAug 27.2006 — No problem... twice.
×

Success!

Help @deep-wood spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...