PhP Test Validity of Numbers
<?php
/*
This PhP script will help you to print check the validity of your numbers
It takes as an input a file which has all the numbers that you wish to verify against
CallFire's Validation API
www.callfire.com/dev/index.php/Rest_API
The script will return you the valid numbers list.
*/
$fileLocation = "ENTER_YOUR_FILE_LOCATION_HERE";
$file = fopen($fileLocation, "r") or exit("Unable to open file!");
$baseUrl = "https://www.callfire.com/cloud/1/utils/getNumberDetails?npanxs=";
$apiKey = "&apikey=YOUR_CALLFIRE_API_KEY";
while(!feof($file)) {
$number = fgets($file);
$num = trim($number);
$url = $baseUrl.$num.$apiKey;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$resp = curl_exec($ch);
//echo $resp."<br/>";
$subject = $resp;
$pattern = '/<resultCount>0/';
$x = preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE);
if($x == 1) {
//Invalid Number
}
else {
//Number is Valid
echo $number."<br/>";
}
}
fclose($file);
?>