
06-05-03, 09:48 AM
|
 |
HotScripts.com Forum Admin
|
|
Join Date: May 2003
Location: 2
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Help with Regex in PHP
Hello All:
I am needing some PHP code that will run a regex on a string (the environmental variable for a users hostname) and return the fully qualified domain name from that string. Below are some examples of strings:
poolf7-029.wwa.com
whatever.sub.sub2.domain.co.uk
morestuff.more-stuff.sub.school.k12.us
You get the idea. If we were looking at just a single .xxx it would be simple, but .com.ty or .co.uk and perhaps even 3-level extensions make this more challenging.
Anyone know of some code that has been written to parse fully qualified domain names out of hostnames?
|

06-05-03, 11:01 AM
|
 |
Newbie Coder
|
|
Join Date: Jun 2003
Location: Canada
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
|

06-06-03, 02:10 AM
|
|
Hot Moderator ;)
|
|
Join Date: Jun 2003
Location: India
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
That is an interesting problem.
Here is what I could come up with.
Try it and see if it works. I think it might not work in some situations and I am right now too lazy to think about those situations.
So if you could populate $domain_names properly and check it, it will be great!
Regards,
JD
__________________
http://www.phpkid.org
|

06-06-03, 02:19 AM
|
|
Hot Moderator ;)
|
|
Join Date: Jun 2003
Location: India
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Okie,
I figured out when my code will break.
Say if you have top qualified domain name like .co.in and .in then it will tell you that top qualified domain name is .in instead of correct '.co.in' . Anyways following code solves the problem!
Hope that helps! 
JD
__________________
http://www.phpkid.org
Last edited by phpkid; 06-06-03 at 02:22 AM.
|

06-06-03, 05:51 PM
|
 |
PHP is my life.
|
|
Join Date: Jun 2003
Location: New Zealand
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
This returns the domains that are real you can modify it to only work on the first domain.
this echo's "netdupe.com" as it is the only real domain.
if you want it to only return the top level domain (no subdomains) you will need to make all the real domains into a string seperated by a comma. should look something like this:
go here for the proper file the forums strip stuff that needs it to work.
http://www.devdino.com/domaincheck.txt
__________________
-Duey
server: irc.chatchannel.org
channel: #hotscripts
Last edited by DuEy; 06-06-03 at 07:35 PM.
|

06-07-03, 01:32 AM
|
 |
PHP is my life.
|
|
Join Date: Jun 2003
Location: New Zealand
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok ive modified it a bit to try and speed the script up, tested and works fine. I enjoyed making this one lol. See attached file.
__________________
-Duey
server: irc.chatchannel.org
channel: #hotscripts
Last edited by DuEy; 06-07-03 at 01:42 AM.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|