i've been answered in my question here :
File_get_contents($url): failed to open stream
, and since i work with that function which was great for performance , now i'm facing a strange problem which is when i have an array in my url , the function stops of working , is there any solution ?
here is an example of the url :
http://website.com/file.php?a=save¶m1=90¶m2=1330¶mS[399]=on¶mT[5]=Mme&Names[2]=Tantan&types[3]=Martine
updated : the function you gived me :
function curl_function($uri) {
$parsed_url = parse_url($uri);
//Create fixed url
$fixed_url = $parsed_url['scheme'] . '://' . $parsed_url['host'] . $parsed_url['path'];
//If exists query
if (isset($parsed_url['query'])) {
$output = array();
$result = array();
//Extract querystring
parse_str($parsed_url['query'], $output);
//Encode values in querystring
forEach ($output as $k => $v) {
$result[] = $k . '=' . rawurlencode($v);
}
//Append encoded querystring
$fixed_url .= '?' . implode('&', $result);
}
//Get result in page
$ch = curl_init();
$timeout = 30; //set to zero for no timeout
curl_setopt($ch, CURLOPT_URL, $fixed_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
$errornum = curl_errno($ch);
$info = curl_getinfo($ch);
$status = (int) $info['http_code'];
if ($errornum !== 0) {
echo 'Error: ', curl_error($ch);
$file_contents = NULL;
} else if ($status !== 200) {
echo 'http_error: ', $status;
$file_contents = NULL;
}
curl_close($ch);
return $file_contents;
}
it doesn't work with the url i wroth above , but when i do a simple file_get_contents($url) it works fine ...
updated : The error i get :
( ! ) Warning: rawurlencode() expects parameter 1 to be string, array given in C:\wamp\www\pretty.php on line 24
Thanks.