Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Domain & Subfolder slicing form URL

0 views
Skip to first unread message

kg3

unread,
Sep 2, 2003, 12:07:28 PM9/2/03
to
Hi,
I am looking for a way where I can get the domain name and subfolders in it sliced out means if somebody types:

eg: http://www.dell.com/support/support.cfm

then I need returned following things:

domain : http://www.dell.com
folder : /support/support.cfm

Also a ccheck if somebody types just http://www.dell.com/ or http://www.dell.com then the value for domain should return as
domain: http://www.dell.com
folder: / or blank

Please let me know if anybody have a way to do this.

Thanks in advance for all the help


mrnate

unread,
Sep 2, 2003, 1:39:16 PM9/2/03
to
ok, i hacked his function a bit. it should do what you want, returning more info than you need... i hope.

Let me know if it works.
<cfscript>

function splitUrl(inUrl) {

var s = inUrl;

var refUrl = "";
var refQS = "";
var refAnchor = "";

var st = structNew();

var i = find("?", s);
if (i) {
refUrl = left(s, i-1);
refQS = mid(s, i+1, 99999);

i = find("##", refQS);
if (i) {
refAnchor = mid(refQS, i+1, 99999);
refQS = left(refQS, i-1);
} else {
refAnchor = "";
}
} else {

i = find("##", s);
if (i) {
refUrl = left(s, i-1);
refAnchor = mid(s, i+1, 99999);
} else {
refUrl = s;
}
}

if (find("?", s) and Find("/",inUrl,9)) {
st.path = Mid(inUrl,Find("/",inUrl,9),find("?", s)-Find("/",inUrl,9));
} else if (find("?", s)) {
st.path = "/";
} else {
st.path = RemoveChars(inUrl,1,Find("/",inUrl,9));
}

st.domain = Left(refUrl,find("/",inUrl,9)-1);

st.url = refUrl;
st.queryString = refQS;
st.anchor = refAnchor;

return st;
}

</cfscript>

<cfset URL_to_split = "http://www.mysite.com/hello/index.cfm?x=1&b=2##a">
<cfset st = splitUrl(URL_to_split)>
<cfdump var="#st#">

-nathan strutz
http://www.dopefly.com/

kg3

unread,
Sep 2, 2003, 1:18:39 PM9/2/03
to
Hi,
I copied the script and now I trying to use it for following URL as a test

<cfset st = splitUrl("http://www.macromedia.com/software/flash/special/buynow.html")>
<cfdump var="#st#">

And I get the results as following

ANCHOR
QUERYSTRING
URL http://www.macromedia.com/software/flash/special/buynow.html


And I am looking for This.

QUERYSTRING /software/flash/special/buynow.html
URL http://www.macromedia.com


Thanks


DeanChalk

unread,
Sep 3, 2003, 6:31:36 AM9/3/03
to
Thats a REALLY long winded way of doing it - try this


<cfset urlstr = "http://www.macromedia.com/software/flash/special/buynow.html">

<cfif find("://",urlstr)>
<cfset urlstr = replacenocase(urlstr,"http://","")>
</cfif>

<cfset domain = "http://" & listfirst(urlstr,"/")>
<cfset querystring = "/" & listrest(urlstr,"/")>

<cfoutput>
#domain# <br>
#querystring#
</cfoutput>

Dean Chalk

0 new messages