You are here: Re: URL Validate « PHP Programming Language « IT news, forums, messages
Re: URL Validate

Posted by Armando Padilla on 08/10/06 06:33

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';
}
===========================================================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация