I want to know how to check a url
if the format of the url is right not wrong
i want to check if the url contain:
xxx.xxx.(com,net,org,co,...).(us,uk,ue,kw,sa,...)
what i should do???
can anyone help me please
I want to know how to check a url
if the format of the url is right not wrong
i want to check if the url contain:
xxx.xxx.(com,net,org,co,...).(us,uk,ue,kw,sa,...)
what i should do???
can anyone help me please
preg_match('/^(http|ftp):\\/\\/([^.?]+.)+/',$string, $matches);
That will check the rough form of the url and place the protocol and domain into $matches[0]. I have to check through the TLD you will have to set up some alternation on the following list.
Location Based TLDs
.ac – Ascension Island
.ad – Andorra
.ae – United Arab Emirates
.af – Afghanistan
.ag – Antigua and Barbuda
.ai – Anguilla
.al – Albania
.am – Armenia
.an – Netherlands Antilles
.ao – Angola
.aq – Antarctica
.ar – Argentina
.as – American Samoa
.at – Austria
.au – Australia
.aw – Aruba
.az – Azerbaijan
.ax – Aland Islands
.ba – Bosnia and Herzegovina
.bb – Barbados
.bd – Bangladesh
.be – Belgium
.bf – Burkina Faso
.bg – Bulgaria
.bh – Bahrain
.bi – Burundi
.bj – Benin
.bm – Bermuda
.bn – Brunei Darussalam
.bo – Bolivia
.br – Brazil
.bs – Bahamas
.bt – Bhutan
.bv – Bouvet Island
.bw – Botswana
.by – Belarus
.bz – Belize
.ca – Canada
.cc – Cocos (Keeling) Islands
.cd – Congo, The Democratic Republic of the
.cf – Central African Republic
.cg – Congo, Republic of
.ch – Switzerland
.ci – Cote d'Ivoire
.ck – Cook Islands
.cl – Chile
.cm – Cameroon
.cn – China
.co – Colombia
.cr – Costa Rica
.cs – Serbia and Montenegro
.cu – Cuba
.cv – Cape Verde
.cx – Christmas Island
.cy – Cyprus
.cz – Czech Republic
.de – Germany
.dj – Djibouti
.dk – Denmark
.dm – Dominica
.do – Dominican Republic
.dz – Algeria
.ec – Ecuador
.ee – Estonia
.eg – Egypt
.eh – Western Sahara
.er – Eritrea
.es – Spain
.et – Ethiopia
.fi – Finland
.fj – Fiji
.fk – Falkland Islands (Malvinas)
.fm – Micronesia, Federal State of
.fo – Faroe Islands
.fr – France
.ga – Gabon
.gb – United Kingdom
.gd – Grenada
.ge – Georgia
.gf – French Guiana
.gg – Guernsey
.gh – Ghana
.gi – Gibraltar
.gl – Greenland
.gm – Gambia
.gn – Guinea
.gp – Guadeloupe
.gq – Equatorial Guinea
.gr – Greece
.gs – South Georgia and the South Sandwich Islands
.gt – Guatemala
.gu – Guam
.gw – Guinea-Bissau
.gy – Guyana
.hk – Hong Kong
.hm – Heard and McDonald Islands
.hn – Honduras
.hr – Croatia/Hrvatska
.ht – Haiti
.hu – Hungary
.id – Indonesia
.ie – Ireland
.il – Israel
.im – Isle of Man
.in – India
.io – British Indian Ocean Territory
.iq – Iraq
.ir – Iran, Islamic Republic of
.is – Iceland
.it – Italy
.je – Jersey
.jm – Jamaica
.jo – Jordan
.jp – Japan
.ke – Kenya
.kg – Kyrgyzstan
.kh – Cambodia
.ki – Kiribati
.km – Comoros
.kn – Saint Kitts and Nevis
.kp – Korea, Democratic People's Republic
.kr – Korea, Republic of
.kw – Kuwait
.ky – Cayman Islands
.kz – Kazakhstan
.la – Lao People's Democratic Republic
.lb – Lebanon
.lc – Saint Lucia
.li – Liechtenstein
.lk – Sri Lanka
.lr – Liberia
.ls – Lesotho
.lt – Lithuania
.lu – Luxembourg
.lv – Latvia
.ly – Libyan Arab Jamahiriya
.ma – Morocco
.mc – Monaco
.md – Moldova, Republic of
.mg – Madagascar
.mh – Marshall Islands
.mk – Macedonia, The Former Yugoslav Republic of
.ml – Mali
.mm – Myanmar
.mn – Mongolia
.mo – Macau
.mp – Northern Mariana Islands
.mq – Martinique
.mr – Mauritania
.ms – Montserrat
.mt – Malta
.mu – Mauritius
.mv – Maldives
.mw – Malawi
.mx – Mexico
.my – Malaysia
.mz – Mozambique
.na – Namibia
.nc – New Caledonia
.ne – Niger
.nf – Norfolk Island
.ng – Nigeria
.ni – Nicaragua
.nl – Netherlands
.no – Norway
.np – Nepal
.nr – Nauru
.nu – Niue
.nz – New Zealand
.om – Oman
.pa – Panama
.pe – Peru
.pf – French Polynesia
.pg – Papua New Guinea
.ph – Philippines
.pk – Pakistan
.pl – Poland
.pm – Saint Pierre and Miquelon
.pn – Pitcairn Island
.pr – Puerto Rico
.ps – Palestinian Territories
.pt – Portugal
.pw – Palau
.py – Paraguay
.qa – Qatar
.re – Reunion Island
.ro – Romania
.ru – Russian Federation
.rw – Rwanda
.sa – Saudi Arabia
.sb – Solomon Islands
.sc – Seychelles
.sd – Sudan
.se – Sweden
.sg – Singapore
.sh – Saint Helena
.si – Slovenia
.sj – Svalbard and Jan Mayen Islands
.sk – Slovak Republic
.sl – Sierra Leone
.sm – San Marino
.sn – Senegal
.so – Somalia
.sr – Suriname
.st – Sao Tome and Principe
.sv – El Salvador
.sy – Syrian Arab Republic
.sz – Swaziland
.tc – Turks and Caicos Islands
.td – Chad
.tf – French Southern Territories
.tg – Togo
.th – Thailand
.tj – Tajikistan
.tk – Tokelau
.tl – Timor-Leste
.tm – Turkmenistan
.tn – Tunisia
.to – Tonga
.tp – East Timor
.tr – Turkey
.tt – Trinidad and Tobago
.tv – Tuvalu
.tw – Taiwan
.tz – Tanzania
.ua – Ukraine
.ug – Uganda
.uk – United Kingdom
.um – United States Minor Outlying Islands
.us – United States
.uy – Uruguay
.uz – Uzbekistan
.va – Holy See (Vatican City State)
.vc – Saint Vincent and the Grenadines
.ve – Venezuela
.vg – Virgin Islands, British
.vi – Virgin Islands, U.S.
.vn – Vietnam
.vu – Vanuatu
.wf – Wallis and Futuna Islands
.ws – Western Samoa
.ye – Yemen
.yt – Mayotte
.yu – Yugoslavia
.za – South Africa
.zm – Zambia
.zw – Zimbabwe
Generic TLDs
.aero - Air-transport industry
.biz - Businesses
.com - Unrestricted (but intended for commercial registrants)
.coop - Cooperatives
.edu - educational institutions
.gov - government
.info - Unrestricted use
.int - Organizations established by international treaties between governments
.mil - military
.museum - Museums
.name - For registration by individuals
.net - Unrestricted (but intended for network providers, etc.)
.org - Unrestricted (but intended for organizations that do not fit elsewhere)
.pro - Accountants, lawyers, physicians, and other professionals
And we haven't even started on the second level domains. :eek: I would suggest that you need to be more certain of a url being correct than just it's form then ping it. Open up a socket to it and see of you get a response.
HTH
Bubble
PS. Thank you very much , I 'd never bothered to actually look up all the TLDs before but it was quite interesting when I did. I also found this which I found rather intresting.
can you please explain what you give me...
because i am tring to do this
preg_match('/^(http|ftp):\/\/([^.?]+.)+/',$string, $matches);
if(empty($matches))
echo "wrong url";
else
print_r($matches);
when i say string="http://www.php.net" , "http://php.net.sa","http://php.net"
it's work
when i say string="www.php.net" it's give me wrong Url
when i say string="http://ramez" it's work and print it( and this what i don't want)
"/^(http|ftp):\/\/([^.?]+\.)+\.)+/"
right, let's break it on down.
/ - this is the starting delimeter, this is the character it looks for to end the regex.
^ - This denotes the begining of the string
(http|ftp) - This is an alternation, it means that there must be either the string "http" or the string "ftp" (in this case, at the start of the string)
:\/\/ - matches :// the backslashes are added to escape the slashes so that the regex engine does not take either of them to be the closing delimiter for the regex
[.?]+ - One or more occurences (+) of any character other than . or ? ([.?])
. - matches a ., escaped because . is a special character matching any character.
+ - that whole bit we want repeated one or more times, always seperated by a dot.
To allow the string www.php.net you would have to say that the first part of the regex (concerning the protocol) is optional. You would do this by pernthesizing it and placing a question mark after it (optional).
/^((http|ftp):\/\/)?([^.?]+\.)+/
HTH
Bubble
thanks for your help
but when i say http://ramez
it say that it's a good url
so how can i solve this problem
Are you sure you've escaped the second period?
Originally posted by ramez_sever
thanks for your help
but when i say http://ramez
it say that it's a good url
so how can i solve this problem
WTB, it CAN BE good URL for local network.
But if you want only common names with .com or something like:
... (?:[a-z0-9-]+.)+[a-z]{2,6}.?$
one or more subdomains and last part from 2 to 6 letters (it was from 2 to 3 in first version - damn on .info and .museum! )