Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 8th, 2006, 10:15 AM
rohit
Guest
 
Posts: n/a
Default URL Validate

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

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles