PHP code example of hlrlookup / php-sdk
1. Go to this page and download the library: Download hlrlookup/php-sdk library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hlrlookup / php-sdk example snippets
use HlrLookup\HlrLookup;
use HlrLookup\Config;
$hlr = new HlrLookup(new Config('your-api-key', 'your-api-secret'));
// Single number lookup
$results = $hlr->hlr('+447540822872');
$result = $results[0];
echo $result->liveStatus->value; // "LIVE"
echo $result->telephoneNumberType->value; // "MOBILE"
echo $result->isLive(); // true
echo $result->isPorted(); // true/false
// HLR Lookup (full live status check) - 1 credit
$results = $hlr->lookups()->hlr('447540822872');
// MNP Lookup (number portability only) - 0.5 credits
$results = $hlr->lookups()->mnp('447540822872');
// Number Validation
$results = $hlr->lookups()->validate('447540822872');
$results = $hlr->hlr('447540822872', '441133910781', '17148307000');
foreach ($results as $result) {
echo $result->detectedTelephoneNumber . ': ' . $result->liveStatus->value . "\n";
}
use HlrLookup\DTO\LookupRequest;
use HlrLookup\Enum\SaveToCache;
$request = new LookupRequest(
telephoneNumber: '447540822872',
cacheDaysPrivate: 30,
cacheDaysGlobal: 15,
saveToCache: SaveToCache::YES,
outputFormat: 'E164',
inputFormat: 'GBR', // ISO3 country code for local numbers
getPortedDate: true, // +1 credit
getLandlineStatus: true, // +1 credit (UK/Ireland only)
usaStatus: true, // +1 credit (USA mobile only)
);
$results = $hlr->hlr($request);
$result = $results[0];
// Status
$result->liveStatus; // LiveStatus enum: LIVE, DEAD, ABSENT_SUBSCRIBER, etc.
$result->telephoneNumberType; // TelephoneNumberType enum: MOBILE, LANDLINE, VOIP, etc.
$result->isPorted; // PortedStatus enum: YES, NO, UNKNOWN
$result->disposableNumber; // DisposableStatus enum: YES, UNKNOWN
// Convenience methods
$result->isLive(); // bool
$result->isDead(); // bool
$result->isPorted(); // bool
$result->isDisposable(); // bool
$result->hasError(); // bool
// Network details
$result->originalNetworkDetails->name; // "O2 (UK)"
$result->originalNetworkDetails->mccmnc; // "23410"
$result->originalNetworkDetails->countryIso3; // "GBR"
$result->currentNetworkDetails->name; // "EE"
// Other fields
$result->creditsSpent; // float
$result->detectedTelephoneNumber; // "447540822872"
$result->formattedTelephoneNumber;// "+447540822872" (when output_format set)
$result->uuid; // unique identifier
$result->timestamp; // "2022-10-07T13:06:15Z"
$result->portedDate; // ISO 8601 date or "NOT_AVAILABLE"
$balance = $hlr->lookups()->balance();
echo $balance->credits; // 150.5
use HlrLookup\DTO\BatchArguments;
$bulk = $hlr->bulk();
// Create a batch
$batch = $bulk->create('my-numbers.csv');
// Upload numbers
$bulk->uploadNumbers($batch->id, ['447540822872', '441133910781']);
// Or upload a file
$bulk->uploadFile($batch->id, '/path/to/numbers.csv');
// Start processing
$bulk->start($batch->id);
// Check status
$batch = $bulk->get($batch->id);
echo $batch->status->value; // "PROCESSING", "COMPLETE", etc.
// Download results
$csv = $bulk->resultsCsv($batch->id);
$results = $bulk->resultsJson($batch->id); // LookupResult[]
// Schedule for later
$bulk->schedule($batch->id, new \DateTimeImmutable('2024-01-15T10:00:00Z'));
// Pause / delete
$bulk->pause($batch->id);
$bulk->delete($batch->id); // irreversible
use HlrLookup\Exception\AuthenticationException;
use HlrLookup\Exception\BadRequestException;
use HlrLookup\Exception\RateLimitException;
use HlrLookup\Exception\ServerException;
use HlrLookup\Exception\ValidationException;
try {
$results = $hlr->hlr('447540822872');
} catch (AuthenticationException $e) {
// 401 - Invalid credentials
} catch (BadRequestException $e) {
// 400 - Invalid parameters
} catch (RateLimitException $e) {
// 429 - Too many requests, retry later
} catch (ServerException $e) {
// 500 - Server error
} catch (ValidationException $e) {
// Client-side validation (e.g., >80 numbers)
}
$config = new Config(
apiKey: 'your-key',
apiSecret: 'your-secret',
referenceId: 'my-ref-123',
accountId: 'my-account',
);
$hlr = new HlrLookup(Config::testing());
$results = $hlr->hlr('441133910781');
bash
composer