Print Page | Close Window

parsing domain from a long url

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=28843
Printed Date: 29 March 2026 at 8:34pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: parsing domain from a long url
Posted By: mhanif
Subject: parsing domain from a long url
Date Posted: 10 September 2010 at 3:37pm
<%
url = " http://" rel="nofollow - http://www.google.com.au/?var=34sa&ada=adklfjadfa&adfaadfa=akdfadfa "
%>
 
 
I want this to return
 
google.com.au
 
 
Please help me, i need this urgent.  just help me with the script which can parse long url into just a domain name.  if url has www, or not,  if domain is google.co.uk or google.com, whatever the extension is.   the result should be
 
like:  google.co.uk
 
Regards



Replies:
Posted By: Scotty32
Date Posted: 15 September 2010 at 6:49pm
Its very simple using a mixture of http://www.w3schools.com/vbscript/func_mid.asp" rel="nofollow - mid , http://www.w3schools.com/vbscript/func_instr.asp" rel="nofollow - Instr and http://www.w3schools.com/Vbscript/func_replace.asp" rel="nofollow - Replace .

-------------
S2H.co.uk - http://www.s2h.co.uk/wwf/" rel="nofollow - WebWiz Mods and Skins

For support on my mods + skins, please use http://www.s2h.co.uk/forum/" rel="nofollow - my forum .


Posted By: mhanif
Date Posted: 15 September 2010 at 11:20pm
Actually i don't know the usage of those which you mentioned. If you can code it here, if its really simple and does not take alot of time for you. I will be thanksful to you. its not for something commercial. I need it for my personal project, and i am just failing to do that. And even in php to asp converter, it is not converting properly. :(


Posted By: Scotty32
Date Posted: 18 September 2010 at 11:39am
Well, if all you want to do is grab the domain name you can use the above links to strip it down like so:

Use the Replace function to remove the "http://" and "www." part like so:

strInput = "http://www.google.com.au/?var=34sa&ada=adklfjadfa&adfaadfa=akdfadfa"
strTmp = replace(strInput,"http://","")
strTmp = replace(strTmp,"https://","")
strTmp = replace(strTmp,"www.","")


Then use the Instr Function to find the first "/" next
(being the end of the domain name now we've removed the "http://" part)

intPos = InStr(strTmp,"/")


Then use Mid to strip the end off like so:

strOutput = Mid(strTmp,1,intPos)


Putting it all together you get:

strInput = "http://www.google.com.au/?var=34sa&ada=adklfjadfa&adfaadfa=akdfadfa"

strTmp = replace(strInput,"http://","")
strTmp = replace(strTmp,"https://","")
strTmp = replace(strTmp,"www.","")

intPos = InStr(strTmp,"/")

strOutput = Mid(strTmp,1,intPos)

Response.Write(strOutput)


The links I provided did explain the functions (which is why I provided them), So you should of been able to do this your self.

And if you know PHP then the http://www.design215.com/toolbox/asp.php" rel="nofollow - this page has helped me go from ASP to PHP.



-------------
S2H.co.uk - http://www.s2h.co.uk/wwf/" rel="nofollow - WebWiz Mods and Skins

For support on my mods + skins, please use http://www.s2h.co.uk/forum/" rel="nofollow - my forum .



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net