I want to get data using CURL but I have a problem. When I set the url like this
$url = "https://graph.facebook.com/fql?q=SELECT name FROM page"; // continues
I do not have anything returned. When I copy the browser url, this is
$url = "https://graph.facebook.com/fql?q=SELECT%20name%20FROM%20page";
I get the results through CURL. I tried htmlentities and htmlspecialchars without luck.
What am I missing here?
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$content = curl_exec($ch);
you would use
urlencode($string);in thecurl_init();or call the urlencode before and set it to a variable like so:example:
php documentation: http://php.net/manual/en/function.urlencode.php
incorrect usage of: htmlspecialchars() and htmlentities()
htmlspecialchars() is used to strip characters and sanitize data in the URI string. use urldecode to decode the %20’s and such into their proper strings.
Conversely use urlencode($string); to convert spaces, slashes, ampersands and other elements into their respective URL friendly counterpart.