faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

11 of 16 people (69%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How to pass a string that contain character "&" between words that display on the url

Feb 24th, 2008 00:06
dman, Kim, Truey Truey, http://www.ttnr.org


Use urlencode on the part that contains the &. (this also works with 
other special characters)
More info:
http://www.php.net/manual/en/function.urlencode.php
Example:
You have the following example:
$url="http://www.foo.bar/test.php?parameter1=value1¶meter2=123&;
Since parameters are separated by '&', the script will take whatever is 
between "parameter2=" and "&", which in this case is "123". If the '&' 
was a part of the value, you could urlencode the value first.
$url = "http://www.foo.bar/test.php?parameter1=value1¶meter2=" + 
urlencode("123&");
Now $url contains an urlencoded string, that the script can use.