function beliefmedia_valid_acn($acn) { $weights = array(8, 7, 6, 5, 4, 3, 2, 1, 0); /* Strip anything other than numbers */ $acn = preg_replace('/[^0-9]/', '', $acn); /* Check string lenth is 9 characters */ if (strlen($acn) != 9) return "false"; /* Add the products */ $sum = 0; foreach (str_split($acn) as $key => $digit) { $sum += $digit * $weights[$key]; } /* Get remainder */ $remainder = $sum % 10; /* Remainder compliment */ $complement = (string)(10 - $remainder); /* If complement is 10, set to 0 */ if ($complement === "10") $complement = "0"; return ($acn[8] === $complement) ? true : false; } function beliefmedia_valid_abn($abn) { $weights = array(10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19); /* Strip anything other than numbers */ $abn = preg_replace('/[^0-9]/', '', $abn); /* 11 characters */ if (strlen($abn) != 11){ return "false";} /* Subtract one from first digit */ $abn[0] = ((int) $abn[0] - 1); /* Add the products */ $sum = 0; foreach (str_split($abn) as $key => $digit) { $sum += ($digit * $weights[$key]); } if (($sum % 89) != 0) { return "false"; } return "true"; } function beliefmedia_jsonp_decode($jsonp, $assoc = true) { if ($jsonp[0] !== '[' && $jsonp[0] !== '{') { $jsonp = substr($jsonp, strpos($jsonp, '(')); } return json_decode(trim($jsonp,'();'), $assoc); } function beliefmedia_abn_lookup($abn, $results = '20', $guid = 'ENTER YOUR GUID NUMBER HERE') { $curl = curl_init(); curl_setopt($curl, CURLOPT_POST, 1); /* ABN or ACN */ if (preg_match('#^[0-9\s?]+$#', $abn)) { /* Strip white space & get length */ $abn = preg_replace('/\s+/', '', $abn); $abn_length = strlen($abn); if($abn_length == "9"){ if (beliefmedia_valid_abn($abn) === false) return false; $url = 'https://abr.business.gov.au/json/AcnDetails.aspx?acn=' . $abn . '&callback=callback&guid=' . $guid; curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($curl); $ddata = beliefmedia_jsonp_decode($result); return $ddata["AbnStatus"]; }else if($abn_length == "11"){ if (beliefmedia_valid_acn($abn) === false) return false; $url = 'https://abr.business.gov.au/json/AbnDetails.aspx?abn=' . $abn . '&callback=callback&guid=' . $guid; curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($curl); $ddata = beliefmedia_jsonp_decode($result); return $ddata["AbnStatus"]; }else{ return false; } /* Else it's a text search */ } elseif (preg_match('#(a-Z0-9\!\?\#\$\&\'\%\(\)\*\?\-/\:\;\=@,.\s\{\|\})*#', $abn)) { $data = @file_get_contents('https://abr.business.gov.au/json/MatchingNames.aspx?name=' . str_replace(' ', '+', $abn) . '&maxResults=' . $results . '&guid=' . $guid); $data = beliefmedia_jsonp_decode($data); $ddata = beliefmedia_jsonp_decode($result); return $ddata["AbnStatus"]; } else { return false; } } $abn = '68076594119'; if(strlen($abn) != 9 && strlen($abn) != "11"){ echo "false"; }else if(beliefmedia_abn_lookup($abn) == "Active"){ echo "true"; }else{ echo "false"; }