jarir-ahmed / bd-mnp
Mobile Number Portability (MNP) lookup for Bangladesh. Detect ported numbers, resolve current and original operators from MNP routing codes, and import MNP CSV data.
Requires
- php: >=7.2
Requires (Dev)
- phpunit/phpunit: ^9.0
Suggests
- ext-pdo: Required for database-backed MNP lookups.
README
Mobile Number Portability (MNP) lookup for Bangladesh. Detect ported numbers, resolve current and original operators from MNP routing codes, and import MNP CSV data. Zero core dependencies.
composer require jarir-ahmed/bd-mnp
Quick Start
use JarirAhmed\BdMnp\MnpLookup; $mnp = new MnpLookup(); // Import MNP data from CSV (from National MNP database) $mnp->importCsv('mnp_data.csv'); // Look up a number $result = $mnp->lookup('01712345678'); // [ // 'number' => '01712345678', // 'ported' => true, // 'recipientRC' => 17, // 'donerRC' => 19, // 'currentOperator' => 'Grameenphone', // 'originalOperator' => 'Banglalink', // 'portedDate' => '2024-01-15', // ]
Or import from arrays:
$mnp = new MnpLookup(); $mnp->importArray([ ['number' => '0171000000', 'recipientRC' => 17, 'donerRC' => 19, 'portedDate' => '2024-01-15'], ['number' => '0182000000', 'recipientRC' => 18, 'donerRC' => 18], // not ported ]);
CSV Format
Required columns (case-insensitive):
| Column | Description |
|---|---|
number |
Phone number prefix (e.g. 0171000000) |
portedDate |
Date the number was ported |
recipientRC |
Current operator Routing Code |
donerRC |
Original operator Routing Code |
nrhRC |
Number Range Holder RC (optional) |
numberType |
Type of number (optional) |
portedAction |
ported or empty (optional) |
API
importCsv(string $file, array $options): int
Import MNP data from a CSV file. Returns entry count.
importArray(array $records): int
Import from an array of associative records.
lookup(string $number): ?array
Look up MNP info. Uses longest-prefix matching. Returns null if not found.
getOperatorName(int $rc): ?string
Resolve a routing code to operator name.
getDefaultOperators(): array
Get the default RC → operator mapping.
clear(): void
Clear all loaded entries.
count(): int
Number of loaded entries.
hasEntries(): bool
Whether any entries are loaded.
Operator Routing Codes
| RC | Operator |
|---|---|
| 7, 13, 17 | Grameenphone |
| 6, 16, 18 | Robi |
| 9, 19 | Banglalink |
| 10, 15 | Teletalk |
| 1, 2, 3, 11 | Citycell |
Testing
composer install
composer test
License
MIT