Log in

View Full Version : getting last part of URL



queerfm
07-04-2009, 07:55 AM
Hi guys,
Just wondering i have made my site so the URL that use to look like this
http://www.dynamicdrive.com/index.php?q=abc
to
http://www.dynamicdrive.com/search/abc

I would like to get the get the last part of the url - abc

I was wondering if anyone would know how?

Jeremy Ross
07-04-2009, 11:09 AM
This php function will help you: http://php.net/manual/en/function.parse-url.php

Turn the path to an array and you should be all set.

molendijk
07-04-2009, 12:40 PM
If you have a file called abc.html, then


<script language="JavaScript">
alert(location.href.substring(location.href.lastIndexOf('/') + 1,location.href.length))
</script>

will give abc.html, and


<script language="JavaScript">
alert(location.href.substring(location.href.lastIndexOf('/') + 1,location.href.length-5))
</script>

produces abc, etc.
===
Arie Molendijk.