Results 1 to 3 of 3

Thread: getting last part of URL

  1. #1
    Join Date
    May 2006
    Posts
    266
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default getting last part of URL

    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?
    The web in one word.

  2. #2
    Join Date
    Jul 2009
    Posts
    4
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default

    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.

  3. #3
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,319
    Thanks
    30
    Thanked 136 Times in 131 Posts
    Blog Entries
    29

    Default

    If you have a file called abc.html, then
    Code:
    <script language="JavaScript">
    alert(location.href.substring(location.href.lastIndexOf('/') + 1,location.href.length))
    </script>
    will give abc.html, and
    Code:
    <script language="JavaScript">
    alert(location.href.substring(location.href.lastIndexOf('/') + 1,location.href.length-5))
    </script>
    produces abc, etc.
    ===
    Arie Molendijk.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •