how to pass strings containing the character "&" in GET

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lenems
Forum Newbie
Posts: 3
Joined: Sun Aug 24, 2008 9:32 pm

how to pass strings containing the character "&" in GET

Post by lenems »

i am relatively new to php and i have a form that uses GET as its method of submitting (to a php file).
now since the character
&
is a reserved character when using GET (used to concatenate
GET variables), if a string containing the & character is submitted as a value to one of my GET variables the program totally does not work.

here is a sample code:

Code: Select all

<a href=\"#\" onClick=\"window.open('http://".$_SERVER['SERVER_NAME'].$DIR_MAIN_FOLDER."/pages/forms/com_communication.form.php?title=".addslashes($uvalue['title'])."&origin_type=".addslashes($default_type)."&datetime_encoded=".addslashes($uvalue['datetime_encoded'])."&operation=update', 'myWin',                        'toolbar=0,status,resizable=0,scrollbars,width=750,height=600,screenX=400,screenY=200');\">
                            <img src=\"".$DIR_IMAGES."/edit4.gif\" title = 'edit'>
                      </a>
in here for example,

Code: Select all

origin_type=".addslashes($default_type)."
my GET variable name is origin_type
the value to be submitted is whatever the value of $default_type

the program does not work if $default_type contains the string &
how can i make the program work even if the & is present and to be submitted as
i don't want to restrict my users not to include the & in their form inputs?

thanks a lot...
lenems
Forum Newbie
Posts: 3
Joined: Sun Aug 24, 2008 9:32 pm

Re: how to pass strings containing the character "&" in GET

Post by lenems »

the character i am referring is "&" ampersand, it seems not displayed correctly, anyway i hope u get the idea... thanks
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: how to pass strings containing the character "&" in GET

Post by Ziq »

To pass & in GET use standard PHP function rawurlencode().

For example:

Code: Select all

 
<?php
$var = 'Simple&test';
echo rawurlencode($var]);
?>
 
lenems
Forum Newbie
Posts: 3
Joined: Sun Aug 24, 2008 9:32 pm

Re: how to pass strings containing the character "&" in GET

Post by lenems »

it works, thanks a lot...
Post Reply