Skip to content

Instantly share code, notes, and snippets.

@TMcManus
Created February 9, 2012 16:21
Show Gist options
  • Save TMcManus/1780889 to your computer and use it in GitHub Desktop.
Save TMcManus/1780889 to your computer and use it in GitHub Desktop.
List Twilio UK Area Codes
<?php
/**
* This script requires a Twilio Account and the Twilio PHP Helper Library,
* which can be found at http://www.twilio.com/docs/libraries
*/
// Require Twilio Helper Library
require('Services/Twilio.php');
// Provide Twilio Account Credentials
$accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$authToken = 'thisistheauthtokenwhichyoushouldnotshare';
// Connect to Twilio's API
$client = new Services_Twilio($accountSid, $authToken);
$i = 10;
$first_four = array();
// Make 20 API calls to Twilio's AvailablePhoneNumbers resource
// Each API call search for a different pair of digits at the beginning of the number
while($i < 30){
$search = '44' . $i;
$params = array('Contains' => $search);
$numbers = $client->account->available_phone_numbers->getList('GB', 'Local', $params);
foreach($numbers->available_phone_numbers as $number) {
$first_four[] = substr($number->phone_number, 3, 4);
}
$i++;
}
// Strip duplicates from array
$first_four = array_unique($first_four);
// Print Results
foreach($first_four as $n){
echo('+44 '.$n.'******');
echo('<br>');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment