vendredi 28 novembre 2014

Can't echo variable from a fucntion


Vote count:

0




i am trying to ping URL, and if successful return URL key in the variable. Whatever url will ping i will use it outside of the function.



<code>
function findUrl(){
$links = array(
'www.anyurl.com/ping' => 'www.anyurl.com',
'http://ift.tt/1uV0SSb' => 'www-01.anyurl.com',
'http://ift.tt/1w2VMdb' => 'www-02.anyurl.com',
'http://ift.tt/1uV0SSf' => 'www-03.anyurl.com'
);
foreach($links as $value => $key){
$ch = curl_init($value);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode>=200 && $httpcode<300){
echo $value; // Does ehco Ping URL
echo $key; // Does echo URL
exit;
} else {echo "Not successful."}
};
echo "didn't work" . "<br>";
}
findUrl(); // run function`
echo $value; // Doesn't return URL. But i somehow need it. `
</code>


Thank you in advance.



asked 36 secs ago







Can't echo variable from a fucntion

Aucun commentaire:

Enregistrer un commentaire