<?php function curl($mail){
$go = curl_init();
$access_token = '1234567890|5fabcd37ef194fee-1752237355|JrG_CsXLkjhcQ_LeYPU.';
curl_setopt($go, CURLOPT_URL,'https://graph.facebook.com/search?q='.$mail.'&type=user&access_token='.$access_token);
curl_setopt($go, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8");
curl_setopt($go, CURLOPT_POST, 0);
curl_setopt($go, CURLOPT_HEADER, 0);
curl_setopt($go, CURLOPT_RETURNTRANSFER, true);
curl_setopt($go, CURLOPT_SSL_VERIFYPEER, false);
$json = curl_exec($go);
curl_close($go);
$arr = json_decode($json,1);
if(isset($arr['data']['0']['id'])) {
return $arr['data']['0']['id'];
} else {
return false;
}
} ?>
I’m placing $name = $arr['data']['0']['name']; right above the return $arr['data']['0']['id']; However I cannot echo the $name variable after I run $a = curl($mail);
Unless you’re updating a global variable (the use of which isn’t best practice) the only way to “access” a variable that’s present within a function/method is if the function/method returns the value you require or accepts the variable by reference as a parameter and updates the variable.
i.e.:
or
This is due to the fact that variables in functions/methods/classes, etc. are only visible within the scope they’re defined with. (This is a good thing.)
You can read more about this at: http://php.net/manual/en/language.variables.scope.php
Incidentally, I’d be tempted not to name a function “curl”, as this is a risky in terms of clashing with an existing function – something like “fetchUserData” might be a better approach.