Connecting Tech Pros Worldwide Help | Site Map

URL Validate

rohit
Guest
 
Posts: n/a
#1: Aug 8 '06
any body can help me to provide the code for URL validate thru PHP

lorento
Guest
 
Posts: n/a
#2: Aug 8 '06

re: URL Validate


$uri = 'http://some-domain-name.org';
if( preg_match(
'/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}'
.'((:[0-9]{1,5})?\/.*)?$/i' ,$uri))
{
echo $uri . ' is a valid url';
}
else
{
echo $uri . ' is NOT a valid url';
}

--
http://www.nusaland.com
http://uk.nusaland.com

rohit wrote:
Quote:
any body can help me to provide the code for URL validate thru PHP
Jerry Stuckle
Guest
 
Posts: n/a
#3: Aug 8 '06

re: URL Validate


lorento wrote:
Quote:
$uri = 'http://some-domain-name.org';
if( preg_match(
'/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}'
.'((:[0-9]{1,5})?\/.*)?$/i' ,$uri))
{
echo $uri . ' is a valid url';
}
else
{
echo $uri . ' is NOT a valid url';
}
>
--
http://www.nusaland.com
http://uk.nusaland.com
>
rohit wrote:
>
Quote:
>>any body can help me to provide the code for URL validate thru PHP
>
>
I'm not a regex expert (barely a beginner) - but two problems with this one.

A uri does not include http or https. That is the protocol being used.
It could be ftp://, for instance.

And this one will fail with some tlds, such as museum.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Armando Padilla
Guest
 
Posts: n/a
#4: Aug 10 '06

re: URL Validate


Jerry Stuckle wrote:
Quote:
lorento wrote:
>
Quote:
>$uri = 'http://some-domain-name.org';
>if( preg_match(
>'/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}'
> .'((:[0-9]{1,5})?\/.*)?$/i' ,$uri))
>{
> echo $uri . ' is a valid url';
>}
>else
>{
> echo $uri . ' is NOT a valid url';
>}
>>
>--
>http://www.nusaland.com
>http://uk.nusaland.com
>>
>rohit wrote:
>>
Quote:
>>any body can help me to provide the code for URL validate thru PHP
>>
>>
>>
>
I'm not a regex expert (barely a beginner) - but two problems with this
one.
>
A uri does not include http or https. That is the protocol being used.
It could be ftp://, for instance.
>
And this one will fail with some tlds, such as museum.
>
loreto, nice work.

aside from the mentioned ".museum" and "ftp" (which can be easily edited
in by using the code below) it looks good.


=== UPDATE regex based off of loreto initial post =====
$uri = 'http://some-domain-name.org';
if( preg_match(
'/^(http|https|ftp):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}'
.'((:[0-9]{1,5})?\/.*)?$/i' ,$uri))
{
echo $uri . 'oh snap! its a valid URL';
}
else
{
echo $uri . 'Wow i hate you....this is not a valid URL';
}
================================================== =========
John Dunlop
Guest
 
Posts: n/a
#5: Aug 10 '06

re: URL Validate


Armando Padilla:
Quote:
Jerry Stuckle wrote:
>
Quote:
A uri does not include http or https. That is the protocol being used.
It could be ftp://, for instance.

And this one will fail with some tlds, such as museum.
>
=== UPDATE regex based off of loreto initial post =====
$uri = 'http://some-domain-name.org';
if( preg_match(
'/^(http|https|ftp):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}'
.'((:[0-9]{1,5})?\/.*)?$/i' ,$uri))
I think you missed Jerry's point. The ftp scheme name was one example.
What are you going to do about other scheme names? For example,
mailto, which doesn't have a '//' authority part. Are you going to
keep track of new scheme names? What about new TLDs?

--
Jock

dawnerd
Guest
 
Posts: n/a
#6: Aug 11 '06

re: URL Validate



rohit wrote:
Quote:
any body can help me to provide the code for URL validate thru PHP
You can always ping the url. If you get a ping back then it is probably
valid :p

Very simple...

Jerry Stuckle
Guest
 
Posts: n/a
#7: Aug 12 '06

re: URL Validate


dawnerd wrote:
Quote:
rohit wrote:
>
Quote:
>>any body can help me to provide the code for URL validate thru PHP
>
>
You can always ping the url. If you get a ping back then it is probably
valid :p
>
Very simple...
>
Yes, but not getting a ping back doesn't mean it's not there. May
servers (including mine) are set to ignore ICMP echo requests (pings).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Pierre Jelenc
Guest
 
Posts: n/a
#8: Sep 8 '06

re: URL Validate


Jerry Stuckle <jstucklex@attglobal.netwrites:
Quote:
dawnerd wrote:
Quote:
You can always ping the url. If you get a ping back then it is probably
valid :p
Yes, but not getting a ping back doesn't mean it's not there. May
servers (including mine) are set to ignore ICMP echo requests (pings).
Send a command to GET headers with http_head(). With ftp, I guess
something with ftp_nlist(). In either case, parse the result appro-
priately.

Pierre



--
Pierre Jelenc | New on Home Office Records: Ethan Lipton
| www.homeofficerecords.com www.ethanlipton.com
The Gigometer | Pepper Of The Earth: the HO blog
www.gigometer.com | www.homeofficerecords.com/blog
Closed Thread