PHP code example of ngarak-dev / nida-parse

1. Go to this page and download the library: Download ngarak-dev/nida-parse 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/ */

    

ngarak-dev / nida-parse example snippets


// The helper function is autoloaded globally
// Analyze a NIDA number (supports both dashed and compact formats)
$ninDashed = "19990504-35710-00001-28";
$ninCompact = "19990504357100000128";

// Get basic information
$info = get_basic_info($ninDashed, null, false);
print_r($info);
// Output: [
//   'BIRTHDATE' => '1999-05-04',
//   'GENDER' => 'FEMALE',
//   'REGIONCODE' => '35',
//   'REGION' => 'MOROGORO',
//   'DISTRICT' => 'MOROGORO URBAN',
//   'WARDCODE' => '35710',
//   'WARD' => 'Mazimbu',
//   'STREET' => '',
//   'PLACES' => '',
// ]

// Get full information with debug
$info = get_basic_info("19990504-35710-00001-28", null, true);

use NidaParse\Services\NidaService;
use NidaParse\Services\LocationLookup;
use NidaParse\Services\NidaParser;

// Parse NIN
$parsed = NidaParser::parse("19990504-35710-00001-28");

// Lookup location
$lookup = new LocationLookup();
$location = $lookup->getAdministrativeHierarchy("35710");

// Get complete info using dependency injection
$service = app(NidaService::class);
$info = $service->getBasicInfo("19990504-35710-00001-28");

use NidaParse\Services\NidaService;

class YourController extends Controller
{
    public function __construct(
        protected NidaService $nidaService
    ) {}

    public function parseNin(string $nin)
    {
        $info = $this->nidaService->getBasicInfo($nin);
        return response()->json($info);
    }
}

return [
    'csv_directory' => storage_path('app/location_files_code'),
    'combined_csv_path' => null, // Set to path of combined CSV if available
];

// Custom CSV directory
$lookup = new LocationLookup('/custom/path/to/csv/files');

// Custom combined file path
$lookup = new LocationLookup(null, '/path/to/combined.csv');
bash
php artisan vendor:publish --tag=nida-parse-csv
bash
php artisan vendor:publish --provider="NidaParse\NidaParseServiceProvider"
bash
php artisan vendor:publish --tag=nida-parse-csv

nida-parse/
├── src/
│   ├── Services/
│   │   ├── LocationLookup.php
│   │   ├── NidaParser.php
│   │   └── NidaService.php
│   ├── Helpers/
│   │   └── nida_helper.php
│   └── NidaParseServiceProvider.php
├── config/
│   └── nida-parse.php
├── resources/
│   ├── location_files_code/
│   │   ├── 11.csv
│   │   ├── 21.csv
│   │   └── ... (other region CSV files)
│   └── tanzania_locations_combined.csv
└── composer.json