https://github.com/labrodev/postal-formatter
PHP 8.1+ utility library that provides robust formatting for European postal codes, following official formatting standards country-by-country.
https://github.com/labrodev/postal-formatter
helper laravel php php-functions php-library php-package php-tools php-utility php8 postal-codes postals web
Last synced: 7 months ago
JSON representation
PHP 8.1+ utility library that provides robust formatting for European postal codes, following official formatting standards country-by-country.
- Host: GitHub
- URL: https://github.com/labrodev/postal-formatter
- Owner: labrodev
- License: mit
- Created: 2025-06-27T10:48:57.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-06-27T11:56:44.000Z (7 months ago)
- Last Synced: 2025-06-27T12:39:54.180Z (7 months ago)
- Topics: helper, laravel, php, php-functions, php-library, php-package, php-tools, php-utility, php8, postal-codes, postals, web
- Language: PHP
- Homepage:
- Size: 0 Bytes
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.MD
- License: LICENSE
Awesome Lists containing this project
README
# PHP Postal Formatter
**Labrodev\PostalFormatter** is a strict PHP 8.1+ utility library that provides robust formatting for European postal codes, following official formatting standards country-by-country.
## Features
- Cleans and standardizes postal codes (removes spaces, symbols, lowercases)
- Supports most of the **European countries** (45+ ISO 3166-1 alpha-2 codes)
- Automatically formats codes to the standard of each country (e.g. `12345` → `123 45` for CZ, `sw1a1aa` → `SW1A 1AA` for GB)
- Ready-to-go static formatter
- Fully typed with strict mode (`declare(strict_types=1)`)
- Includes PHPUnit and PHPStan support for testing and analysis
## Installation
```
composer require labrodev/postal-formatter
```
## Usage
```php
use Labrodev\PostalFormatter\Utilities\PostalFormatter;
// Default usage: just clean and normalize
echo PostalFormatter::format(' 12345 '); // "12345"
// With country-specific formatting:
echo PostalFormatter::format('12345', 'CZ'); // "123 45"
echo PostalFormatter::format('sw1a1aa', 'GB'); // "SW1A 1AA"
echo PostalFormatter::format('1050', 'LV'); // "LV-1050"
```
List of available country codes you may find in CountryCode Enum (Labrodev/PostalFormatter/Enums/CountryCode).
## Testing
To run tests:
```
composer install
composer test
```
## Static Analysis
To run static analysis using PHPStan:
```
composer install
composer analyse
```
> Configuration is located in `phpstan.neon.dist`
## Security
If you discover a security vulnerability within this package, **please contact us immediately at [contact@labrodev.com](mailto:contact@labrodev.com)**. All security-related issues will be handled privately and promptly.
## Credits
This package is maintained by **Labrodev** — Laravel & PHP development studio.
[https://github.com/labrodev](https://github.com/labrodev)
## Feedback
If you have any questions, suggestions, or have found an error — feel free to open an issue or contact us:
📬 **contact@labrodev.com**
**License:** MIT