Connecting Tech Pros Worldwide Help | Site Map

URL Validate

  #1  
Old August 8th, 2006, 10:15 AM
rohit
Guest
 
Posts: n/a
any body can help me to provide the code for URL validate thru PHP

  #2  
Old August 8th, 2006, 10:35 AM
lorento
Guest
 
Posts: n/a

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
  #3  
Old August 8th, 2006, 12:25 PM
Jerry Stuckle
Guest
 
Posts: n/a

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
==================
  #4  
Old August 10th, 2006, 07:25 AM
Armando Padilla
Guest
 
Posts: n/a

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';
}
================================================== =========
  #5  
Old August 10th, 2006, 12:25 PM
John Dunlop
Guest
 
Posts: n/a

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

  #6  
Old August 11th, 2006, 06:15 PM
dawnerd
Guest
 
Posts: n/a

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...

  #7  
Old August 12th, 2006, 03:35 AM
Jerry Stuckle
Guest
 
Posts: n/a

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
==================
  #8  
Old September 8th, 2006, 06:25 AM
Pierre Jelenc
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Method Name Suggestion: Validate a Poor Choice? Mike Hofer answers 24 October 21st, 2007 10:45 PM
Method Name Suggestion: Validate a Poor Choice? Mike Hofer answers 24 October 21st, 2007 10:45 PM
Method Name Suggestion: Validate a Poor Choice? Mike Hofer answers 24 October 21st, 2007 10:45 PM
Page.Validate Jim Heavey answers 5 November 18th, 2005 03:49 PM