How would I make a regular expression that checked if input was a valid website?
Like
http://www.blah.com would be valid
but i still want urls like:
http://www.blah.com/foo/
http://www.blah.com/foo
http://www.blah.com/
http://www.blah.com/foo/
http://www.blah.com/foo
http://www.blah.com/
http://www.blah.com
http://foo.blah.com
http://foo.blah.com/
to all work..
how would i do this?
sorry if these seems more like "make me a regexp!" :-/ but they totally confuse me
Regex(pert) Needed
Moderator: General Moderators
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
There's a user comment on the preg_match() man page which has a regex which can be (apparently) used to separate a URL out into its constituent parts (and there's an explanation).
Mac
Mac
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
stole one from phpbb 
Code: Select all
if ( !preg_match('#^http:\/\/#i', $site) )
{
$site = 'http://' . $site;
}
if ( !preg_match('#^http\\:\\/\\/їa-z0-9\-]+\.(їa-z0-9\-]+\.)?їa-z]+#i', $site) )
{
$site = '';
}- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
Why not just do this?
Code: Select all
preg_match('/^(їa-z]+:\/\/|www\.)/i', $input)