hariadi / siapa
A simple PHP library for parsing complex Malay names into their individual components
Requires
- php: ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.75
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^9.6
README
Malay Name Parser A smart parser for extracting components from complex Malay names:
- โ Salutation
- โ First Name
- โ Last Name (excluding patronyms like "bin"/"binti")
- โ Gender detection
๐ก Example Usage
use Hariadi\Siapa\Siapa; $siapa = Siapa::name("Dato' Dr. Ir. Hj. Hariadi Bin Hinta"); echo $siapa->salutation(); // Dato' Dr. Ir. Hj. echo $siapa->first(); // Hariadi echo $siapa->last(); // Hinta echo $siapa->gender(); // M
๐ฆ Install
Install via Composer:
composer require hariadi/siapa
Then include the autoloader:
require 'vendor/autoload.php';
Alternatively, require the class manually:
require_once 'path/to/Siapa/src/Siapa.php';
๐งฑ Object-Oriented Usage
use Hariadi\Siapa\Siapa; $siapa = Siapa::name('Hariadi Hinta', 'UTF-8'); echo $siapa->first(); // Hariadi
๐งช Methods
If
$encoding
is not provided, it defaults tomb_internal_encoding()
.
salutation()
Returns the full salutation, if detected.
Siapa::name('Datuk Dr. Ir. Hariadi Hinta')->salutation(); // Datuk Dr. Ir.
givenName(bool $withMiddle = false)
Returns full name without salutation. Optionally excludes middle markers (e.g., bin, binti).
Siapa::name("Dato' Hariadi Bin Hinta")->givenName(); // Hariadi Hinta Siapa::name("Dato' Hariadi Bin Hinta")->givenName(true); // Hariadi Bin Hinta
first()
Returns the detected first name:
Siapa::name('Hariadi Hinta')->first(); // Hariadi
last()
Returns the last name (without bin/binti):
Siapa::name('Hariadi Bin Hinta')->last(); // Hinta
gender(bool $short = true)
Detects gender. Returns 'M'
/'F'
or 'Male'
/'Female'
.
Siapa::name('Pn. Nurul Hidayah')->gender(); // F Siapa::name('Pn. Nurul Hidayah')->gender(false); // Female
Gender Detection Heuristics
-
Defaults to Male
-
If last name contains any of:
Binti
,Bte
,A/P
,Pn.
,Puan
,Cik
etc.
-
If salutation contains female honorifics
-
If first name matches any name in
female.txt
โ Tests
Run tests using PHPUnit:
git clone https://github.com/hariadi/Siapa.git
cd Siapa
vendor/bin/phpunit
๐ License
Released under the MIT License.