Page 1 of 1

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

Posted: Sun Aug 24, 2008 9:46 pm
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...

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

Posted: Sun Aug 24, 2008 9:49 pm
by lenems
the character i am referring is "&" ampersand, it seems not displayed correctly, anyway i hope u get the idea... thanks

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

Posted: Mon Aug 25, 2008 1:04 am
by Ziq
To pass & in GET use standard PHP function rawurlencode().

For example:

Code: Select all

 
<?php
$var = 'Simple&test';
echo rawurlencode($var]);
?>
 

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

Posted: Mon Aug 25, 2008 2:15 am
by lenems
it works, thanks a lot...