473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

URL Validate

any body can help me to provide the code for URL validate thru PHP

Aug 8 '06 #1
7 12801
$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:
any body can help me to provide the code for URL validate thru PHP
Aug 8 '06 #2
lorento wrote:
$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:
>>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.
js*******@attglobal.net
==================
Aug 8 '06 #3
Jerry Stuckle wrote:
lorento wrote:
>$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:
>>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';
}
================================================== =========
Aug 10 '06 #4
Armando Padilla:
Jerry Stuckle wrote:
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

Aug 10 '06 #5

rohit wrote:
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...

Aug 11 '06 #6
dawnerd wrote:
rohit wrote:
>>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.
js*******@attglobal.net
==================
Aug 12 '06 #7
Jerry Stuckle <js*******@attglobal.netwrites:
dawnerd wrote:
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
Sep 8 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: SHC | last post by:
Hi all, I have a VC++ .NET 2003 - Windows XP Pro PC. I created a Win32 console application in my VC++ .NET 2003 and copied validateDOM.cpp, books.xml and books.xsd (see the attached files below)...
5
by: Jim Heavey | last post by:
When should you use the Page.Validate() method? I thought you would use this method if you have some Server side validation (CustomControl's) you wanted to use and this would cause them to be...
11
by: jjbutera | last post by:
I know how to use the ErrorProvider in my winforms..or do I? I validate the values and set the ErrorProvider in the validating event. If not valid, I set e.Cancel = True. I clear the ErrorProvider...
0
by: Marc Scheuner | last post by:
Folks, I'm faced with a dilemma here - I have an XML document and for part of it, I have an XSD schema to validate it - but not for the rest of it. Can I still validate at least part of the...
4
by: Brybot | last post by:
I have a form that i've split up into multiple asp:panels, each panel has a number of validators which work correctly. At on the last panel, i want to commit the data collected to a database. I...
24
by: Mike Hofer | last post by:
Please forgive the cross-post to multiple forums. I did it intentionally, but I *think* it was appropriate given the nature of my question. I'm working on an open source code library to help...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.