Sending an Url to my Api via GET
I want to create my own JSON API with PHP and I want that the user can send Text to my API, especially one or more Links. So the Problem is, that this call could look something like this (in a worse case)
http://www.my.site/test.php?link[]=http://stac开发者_JS百科koverflow.com/?as=2&bs=2&link[]=http://stackoverflow.com/?af=2&bf=2
The problem is, that I get only a shorter link without the last information (here: bs=2 and bf=2). This information is threated as GET data. How can I fix this? Must I use any escaping here?
Use urlencode:
echo 'http://www.my.site/test.php?link[]=' .
urlencode('http://stackoverflow.com/?as=2&bs=2') . '&link[]=' .
urlencode('http://stackoverflow.com/?af=2&bf=2')
You should use the urlencode PHP's function.
http://fr.php.net/manual/en/function.urlencode.php
精彩评论