Skip to content

baikho/belgian-address-parser-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Belgian Address Parser PHP

Latest Version on Packagist Total Downloads MIT Licensed GitHub issues GitHub stars

A Belgian address parser library in PHP.

Requirements

  • PHP 8.1 or higher

Installation

You can install the package via composer:

composer require baikho/belgian-address-parser-php

Usage

// Create a parser instance
$parser = new \Baikho\BelgianAddressParser\Parser();

// Parse an address
$parsed = $parser->parse('Andreas Vesaliusstraat 47, 3000 Leuven, België');

// Output the parsed components
print_r($parsed);
Array
(
    [recipient] => 
    [street] => Andreas Vesaliusstraat
    [number] => 47
    [box] => 
    [postal_code] => 3000
    [city] => Leuven
    [country] => België
)

// Validate the address
$validation = $parser->validate($parsed);
if ($validation['valid']) {
    echo "Address is valid!\n";
} else {
    echo "Address has issues: " . implode(', ', $validation['errors']) . "\n";
}

// Format the address back to string
$formatted = $parser->format($parsed);
echo $formatted;