I want to pass a url as a parameter in my PHP script. The URL is coming from my Android app which passes a url and the PHP script custom formats XML to return to the app. So I would pass the url I wanted to format and the PHP script would do stuff and echo the results.
For instance I want to pass this url:
differentwebpage.com/search/?query=ford%20f150&
in my php script (mywebpage.com/script.php):
$url = $_GET['url'];
$str = file_get_contents($url);
echo $str;
So the full url would be:
mywebpage.com/script.php?url=differentwebpage.com/search/?query=ford%20f150&
But this doesn’t work. I think I need to URL encode/decode but I haven’t had any success. How can I pass a full URL as a parameter?
Try encoding it in Android when you pass it.
You can encode using the
URLEncoderhere: http://developer.android.com/reference/java/net/URLEncoder.htmlYou can then easily unencode it in PHP using
urldecode.