I am having a hard time finding out how to get a function to return a variable that I can use outside of the function, I have tried
return $response
and I have tried
return $response = $anothervariable
But the only way I have been able to get it to work is to echo the response and just put the html in there, I know there is a better way to do this, the problem is I can't figure it out. Any help would be appreciated!
function OpenCNAM($ph) {
$opencnamSID = '*****';
$opencnamTOKEN = '*****';
$query = "https://api.opencnam.com/v2/phone/".$ph."?format=text";
if(isset($opencnamSID)) { $query = "https://".$opencnamSID.":".$opencnamTOKEN."@api.opencnam.com/v2/phone/".$ph."?format=text"; }
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $query);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt ($ch, CURLOPT_TIMEOUT, 3);
$response = curl_exec($ch);
curl_close($ch);
if($response != "") {
echo '<span title="'.$response.'"> 888-452-1505</span>';
} else {
echo 'Nada';
}
}
OpenCNAM('8884521505');