SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Dec 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [solved] Passing ? and = in links/URLs

    I have a snippet of code that reads

    PHP Code:
        $date_query $url .'/'$year .'/'$month .'/'$day;

        
    $date_path_array[] = $date_query;
        
    $date_path_array[] = 'mini=' $year .'/'$month;
                
        
    $mini_url implode('?'$date_path_array); 
    When I return $mini_url, I get a path that looks like
    localhost/calendar_ev/2008/12/10%3Fmini%3D2008/12
    But I'd like it to look instead like
    localhost/calendar_ev/2008/11/16?mini=2008/11
    The status bar reads the latter when I mouse over my link, but it appears as the former in the address bar when I actually click on it. Of course, that changes the query, and the desired page does not appear...

    Is there anything I can do to make sure my & and = do not turn into their html-safe counterparts?

    The implode was actually sort of a last-try thing, hoping it would let me pass the ?.
    Last edited by Heavenguard; Dec 2, 2008 at 13:16.

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Welcome to the forums

    Before we can answer, we need you to answer the following:

    What's the HTML output of the link?
    What's the code you're using to actually output this?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Use urldecode() (or, don't use urlencode() earlier in the script if this is happening)

  4. #4
    SitePoint Addict
    Join Date
    Jul 2008
    Location
    sudo rm -rf /
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For query string values use urlencode() ?q=urlencode($s). For paths use rawurlencode() http://www.example.com/ . rawurlencode('example & example').

  5. #5
    SitePoint Member
    Join Date
    Dec 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Truth be told, I'm working within a Drupal site, trying to modify existing functions. I'm still new to the site I'm working on, so I'm not totally familiar with all the workings. (I've been playing a lot of function tag lately...)

    The HTML output is
    <a href="/calendar_ev/2008/12/29%3Fmini%3D2008/12">29</a>
    Which is less than desirable for me.

    The return snippet is
    PHP Code:
    if ($selected) {
         return 
    '<div class="mini-day-on">'l($day$mini_urlNULL$append) .'</div>';

    In this case, $append is an empty variable.

    Would the proper way to use urldecode be:
    PHP Code:
        $date_query $url .'/'$year .'/'$month .'/'$day;

        
    $date_path_array[] = $date_query;
        
    $date_path_array[] = 'mini=' $year .'/'$month;
                
        
    $mini_url urldecode(implode('?'$date_path_array)); 
    ?

    Thanks, I'm no coder by training. I just happen to know enough so that I was asked to fix up a website, and it's been making my life difficult :P

  6. #6
    SitePoint Evangelist
    Join Date
    May 2006
    Location
    Denmark
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It looks like you have to put the query string in $append instead.

  7. #7
    SitePoint Member
    Join Date
    Dec 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'd think it'd be that simple, wouldn't you?

    You'd be absolutely correct.

    $append was associated with another function that I didn't even consider.

    Thanks a lot, you guys!

    I'm going to smack myself in the forehead now.


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
  •