Company Name to Domain with Clearbit API in PHP

This simple function allows you to pass a domain name to it and it will return a bunch of matches with domain names. In this, I’ve set it to just return the first result but you could alter. Very handy! Good time saver.

function getdomainnow($company) {

$ch = curl_init("https://autocomplete.clearbit.com/v1/companies/suggest?query=$company");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);

$result = json_decode($data, true);
$result2 = [];

return $result[0];
}