Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts

    need help with urlencode

    Is it possible to urlencode a URL via $_GET? Cause i've tried it..... doesn't seem to work, while $_POST works perfectly.

    I've noticed the character '#' being left out (and everything behind it) e.g. www.domain.com/files/list.htm#thelist , so 'thelist' dissapears including the '#'.

    Code:
    $url = urlencode($_GET['url'])

    Anyone?

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    That code will encode a variable named in a query string like so:
    http://www.whatever.com/page.php?url=something&another=nothing

    I don't think you understand exactly what the $_GET array consists of. You may be wanting to use $_SERVER['REQUEST_URI']

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by kbluhm View Post
    That code will encode a variable named in a query string like so:
    http://www.whatever.com/page.php?url=something&another=nothing

    I don't think you understand exactly what the $_GET array consists of. You may be wanting to use $_SERVER['REQUEST_URI']
    Well, correct me if i'm wrong, but $_GET['url'] gets the string from ?url e.g. ?url=www.somethingblah.com right? I'm somewhat confused right now...

  • #4
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    Try rawurlencode instead.

  • #5
    New Coder
    Join Date
    Aug 2007
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Mwnciau View Post
    Try rawurlencode instead.
    Hmm that didn't work either, it doesn converts all other chars EXCEPT '#'... damn that '#' is a pain in the *** lol, looks like PHP just sees '#' as a comment (and ignores the rest) when recieved via the browser.

  • #6
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    PHP Code:
    str_replace('#''%23'urlencode($string)); 

  • #7
    New Coder
    Join Date
    Aug 2007
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Mwnciau View Post
    PHP Code:
    str_replace('#''%23'urlencode($string)); 
    Again... no luck

    current code:

    Code:
    $url = $_GET['url'];
    $url = str_replace('#', '%23', urlencode($url));
    It does convert ':' and '/' from http:// nicely, but when it comes to '#' it totally ignores it... odd

  • #8
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    Just tried it and just urlencode on it's own works fine for me

  • #9
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    I don't think the pound (#), or anything after it is even sent to the server. It's used by the browser to jump to an anchor.

  • #10
    New Coder
    Join Date
    Aug 2007
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Inigoesdr View Post
    I don't think the pound (#), or anything after it is even sent to the server. It's used by the browser to jump to an anchor.
    Is this right? Because i am thinking the same way... can anyone confirm this? (That the server cannot recieve '#' from the browser)

  • #11
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Yeah, I was right. You can test it(I did) or do a search and find some links with confirmation:

    http://www.webmasterworld.com/forum92/528.htm


  •  

    Posting Permissions

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