Pass a variable

Discussion in 'PHP' started by marcelocr2, Jul 9, 2008.

  1. #1
    hi, i want to pass a variable using trough the url, burt the problem is that the variable has an &.

    my_var='f&g';
    so, when i use get to recover it, i only see the f

    what can i do to have the & in my variable???

    thank you
     
    marcelocr2, Jul 9, 2008 IP
  2. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #2
    my_var=f%26g

    If you went to google and searched for & , you would see the url encoding in the url....see the q=%26 ?
    Easy way to get the url encoding.

    
    http://www.google.com/search?hl=en&q=%26&btnG=Google+Search
    
    Code (markup):
     
    shallowink, Jul 9, 2008 IP
  3. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #3
    $my_var = urlencode($my_var);
    
    echo $my_var; // So you can see.
    PHP:
    Dan
     
    Danltn, Jul 9, 2008 IP
  4. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #4
    
    echo str_replace('my_var=','',$_SERVER['QUERY_STRING']);
    
    PHP:
    Peace,
     
    Barti1987, Jul 9, 2008 IP