2012-08-12 3 views
2

Je ne souhaite pas utiliser cette fonction car son indisponibilité sur certains serveurs pour des raisons de sécurité, comment puis-je remplacer file_get_content() avec cURL?Remplacer file_get_content() avec cURL?

La ligne ci-dessous me cause un problème sur mon serveur:

$response = file_get_contents('http://images.google.com/images?hl=en&q=' . urlencode ($query) . '&imgsz=' . $size . '&imgtype=' . $type . '&start=' . (($page - 1) * 21)); 

Comment puis-je remplacer la ligne par un autre qui utilise boucle pour qu'il fonctionne sur chaque serveur?

Répondre

7

ici est une fonction propre, vous pouvez utiliser

$response = get_data('http://images.google.com/images?hl=en&q=' . urlencode ($query) . '&imgsz=' . $size . '&imgtype=' . $type . '&start=' . (($page - 1) * 21)); 

function get_data($url) 
{ 
    $ch = curl_init(); 
    $timeout = 5; 
    curl_setopt($ch,CURLOPT_URL,$url); 
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); 
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); 
    $data = curl_exec($ch); 
    curl_close($ch); 
    return $data; 
} 
+0

Où est la variable qui doit être utilisé au lieu de $ response? –

+0

et retour retournera les données – themis

+0

Fonctionne comme un champion! Merci –

Questions connexes