lukaswhite/transliterator

A PHP library for transliterating strings

dev-master 2018-09-24 12:38 UTC

This package is auto-updated.

Last update: 2024-10-28 00:29:48 UTC


README

Transliterate strings with PHP (7+); e.g. remove accented characters.

So "Liberté" becomes "Liberte", "nåløye" becomes "naloeye", and so on.

Installation

Install using Composer:

composer install lukaswhite\transliterator

Usage

use Lukaswhite\Transliterator\Transliterator;

$transliterator = new Transliterator( );

print $transliterator->run( 'Liberté' );
// outputs Liberte

print $transliterator->run( 'nåløye' );
// outputs naloeye

Advanced Usage

Internally, the class maintains a table of character mappings. To get it, for example to inspect it:

var_dump( $transliterator->getTable( ) );

To add a substitution:

$transliterator->addToTable( 'a', 'b' );

To remove a substitution:

$transliterator->removeFromTable( 'a' );

To replace the whole table:

$transliterator->setTable(
	[
		'á' => 'a',
		'é' => 'e',
		'è' => 'e',
	]
);

Credits

This package is based on this answer on Stackoverflow.