/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Check String for http://

I’m trying to check a string for http:// or https://

What would be the easiest way about doing this? If it doesn’t include that, I plan on inserting it to the beginning of the string.

Any advice will be gladly accepted. ?

-Ross (h3r0)

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@pcthugMay 10.2007 — If you are attempting to append the http protocol identifier to the beginning of strings that do not start with either http:// or https:// use:[code=php]$url = !preg_match('/^https?:///', $url) ? "http://$url" : $url;[/code]
Copy linkTweet thisAlerts:
@bokehMay 10.2007 — [code=php]$url_parsed = parse_url($url);
if ( empty($url_parsed['scheme']) )
{
$url = 'http://'.$url;
}[/code]
This takes into account any valid protocol (such as [I]ftp://[/I]).
Copy linkTweet thisAlerts:
@h3r0authorMay 22.2007 — [code=php]$url_parsed = parse_url($url);
if ( empty($url_parsed['scheme']) )
{
$url = 'http://'.$url;
}[/code]
This takes into account any valid protocol (such as [I]ftp://[/I]).[/QUOTE]

Yes, this is exactly what I am looking for. Thanks a lot ?
×

Success!

Help @h3r0 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,
)...