Issue with ampersand in URL

Discussion in 'PHP' started by byteventures, Oct 28, 2008.

  1. #1
    I have been encountering an issue where the ampersand (&) in my string is being passed through to the URL, and subsequently cut off in the browser. Is there a way to convert the ampersand in my string to "%26"? Or is there another solution?

    Here's the code I'm working with.

    $lcname= ($cname);
    		$catlist.="<tr><td valign='top'><h3><a href='".SITEROOT."search.php?keyword=".$lcname."'></a>
    PHP:
    The URL will appear as www.site(dot)com/search.php?keyword=up_&_down
    The search will appear as "up_" and is missing the &_down part.

    Any help would be greatly appreciated. Thanks in advance for your comments.
     
    byteventures, Oct 28, 2008 IP
  2. wendallb

    wendallb Active Member

    Messages:
    180
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    78
    #2
    Try &amp;

    Use this instead of &
     
    wendallb, Oct 28, 2008 IP
  3. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #3
    convert it to %26.

    use urlencode()

    $lcname= ($cname);
            $catlist.="<tr><td valign='top'><h3><a href='".SITEROOT."search.php?keyword=".urlencode($lcname)."'></a>
    PHP:

    The & is still there
     
    ads2help, Oct 28, 2008 IP
  4. byteventures

    byteventures Guest

    Messages:
    200
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Ads2Help - That was exactly what I had been looking for. I couldn't remember how to put it together. Thanks!
     
    byteventures, Oct 28, 2008 IP