Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/forums/php/)
-   -   Php getting argument using $_GET (http://www.go4expert.com/forums/php-getting-argument-using-t14876/)

rekha 30Oct2008 12:40

Php getting argument using $_GET

I have a php page where i am getting argument from another page.The argument contains values similar to "Repair & Maintenance".If i retrieve that argument using $_GET method i am getting only "Repair" as the value.I need the value to be "Repair & Maintenance".How can i get this.


shabbir 30Oct2008 13:24

Re: Php getting argument using $_GET
You submitted the thread as article and I have moved it to forums for discussion.

pete_bisby 17Nov2008 00:13

Re: Php getting argument using $_GET
The ampersand is causing the break in the URL - PHP populates the $_GET array from the URL. Everything to the right of the question mark goes to the $_GET array, with each pair of key/values.
$_GET["field1"] = "value1"
$_GET["field2"] = "value2"

Now because you have an ampersand in the URL, PHP thinks it is a new variable, which is the reason why the second half is disappearning.

The solution: encode the URL correctly - look at htmlentities(), htmlspecialchars() or urlencode()

pradeep 17Nov2008 10:54

Re: Php getting argument using $_GET
Use urlencode

Code: PHP

$url = "http://www.go4expert.com/index.php?value=".urlencode('Repair & Maintenance');

All times are GMT +5.5. The time now is 10:53.