Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting A Domain From A URL 1

Status
Not open for further replies.

Rebies

Programmer
Mar 7, 2002
58
0
0
US
Hey all. I have a list of URLs and need to get the domain (something.com, one.co.uk, etc.net) from that URL but am having a tricky time because there is an ever growing list of available extensions. It also complicates things having extensions with more then 1 dot like ".co.uk". It also complicates things having an infinate amount of subdomains and not just " Has anyone done this before? How would it be accomplished?

I'm thinking this is how it would be done, but not sure:

1: Remove " and "2: If there are any more slashes, remove them and everything else after that from the URL
3: Where to go from here? We have the site (something.site.co.uk), but what would be the next logical step? Ideally I would like to do it without having to list each domain extension, but not sure if this is possible.

Thanks for any help.

Andrew
 
i would try #GetToken(url,3,"/")#

the first token is the protocol (http: or https:)

the second token is a zero-length (empty) string, i.e. the string between the two slashes in http:// or https://

the third token is the host name

rudy
SQL Consulting
 
Actually..

I checked livedocs on this and someone said that if two delimiters occur in a row, it considers it one delimiter..

I checked for myself and rather than #GetToken(url,3,"/")#, he would actually need #GetToken(url,2,"/")#.

But for whatever that's worth (or not) Rudy's right.. ListGetAt (with the same syntax) would work.

There is no better way to parse the urls.. though because nearly all protocols use the :// in them, it would help you to say..

<cfif url contains "://">
#GetToken(url,2,"/")#
<cfelse>
#ListFirst(url,"/")#
</cfif>

ListFirst will get all text before the first "/" for instance if there's a folder path after the domain.. and in the case that there's not, it will just get all text.

Later

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Yeah, pretty much a flaw I'd say..

But its been that way so long, its practically a feature.. If MM changed it now, it'd kill only-God-knows-how-many apps that use list(get/set/delete)at functions and such.

Makes matching things up very hard sometimes, Because of that don't like dealing with string lists.

With numerical lists 1,2,3,4 its easier, I can just run a replace to fix it.. something like..

#replace(nums,",,",", ,","ALL")#

Ya know?

Anyway so now we're venturing off topic but since you thought of the solution, and its not one I would have, I prefer the listgetat function, you get my vote.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Probably just another way MM is trying to help you out. kind of like how it replaces single quotes in variable values in sql. Causes more confusion than anything if users don't know when to use preservesinglequotes(). You'd think they'd make a preserveDelims() function or something. especially if you are expecting say 6 elements you could check to see if the 4th was empty. that would make validation easier... but nooooo.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
I think Bombboy speaks for all of us..

That's like the ever-famous connectstring for CF 5.. I mean I know they yanked it because they switched to a java base but that didn't... impress a lot of smaller site programmers who relied on it.

My biggest beef though is them talking about removing slower functions.. ok that's great and everything except some programmers use them quite a bit.. Its not so hard to just leave it in.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
amen webmigit,
I know a few programers that will not use cf because of the lack of dsnless connections limiting portibility of entire sites. I help run a hosting biz that offers an estore with the hosting, the store has apx 2000 users, imagine having to keep up with the dsn's had it been written in cf. It's currently in asp using dsnless connections and server.mappath to create the connection string.

CF is on the brink of making it TOO easy. programmers of other languages expect something to work a certian way, such as empty elements, or single quotes in sql. when mm start messing with that "universal" behavior for the sake of making it easy, it starts getting hard...

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
I wrote a cc gateway a short while ago and then had to move it to another system with the same users but different userIDs, userIDs being what the system relied on.. so ok, it was a mess to dynamically tie it all together.

I could have taken MM's approach and just not worried about it, let cc funds go awry into other accounts and life would have been easier.

The thing is, PreserveSingleQuotes should work in reverse.. when a n00b (even we were n00bs once once :)) generates an sql string, they assume it should work but even they know that using operating characters in sql for other purposes would screw it, THEN and only THEN would they go searching for a function or a tag or a tip on how to keep the single quotes safe, or rather, preserve them.

The most essential problem with PSQ() is that if you output the string in text it shows correctly and if you copy the gen'd text, the sql works.. I remember years ago slamming my head into my desk over it, my desk still has the indentions to prove it.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
wow.
we ended a bit off topic huh? what were we talking about again? lol.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top