lasserafn/php-initials

A package to generate initials in PHP

Maintainers

πŸ‘ lasserafn

Package info

github.com/LasseRafn/php-initials

pkg:composer/lasserafn/php-initials

Statistics

Installs: 4 954 465

Dependents: 4

Suggesters: 0

Stars: 41

Open Issues: 2

3.1 2020-12-24 12:25 UTC

Requires

  • php: ^5.6|^7.0|^7.1|^8.0

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT d287e1542687390eb68de779949bc0adc49e2d52

  • Lasse Rafn <lasserafn.woop@gmail.com>

phpInitials

This package is auto-updated.

Last update: 2026-06-23 21:00:15 UTC


README

This is the core of LasseRafn/php-initial-avatar-generator, or well.. the initials generation part of it.

It's framework agnostic, which is different from basically everything else I do, you're welcome.

Supports UTF8 (yes, also emojis.)

πŸ‘ Code Coverage
πŸ‘ StyleCI Status
πŸ‘ Total Downloads
πŸ‘ Latest Stable Version
πŸ‘ License

Installation

You just require using composer and you're good to go!

composer require lasserafn/php-initials

Usage

As with installation, usage is quite simple. Generating a image is done by running:

use LasseRafn\Initials\Initials;

echo (new Initials('Lasse Rafn')); // Output: LR
echo (new Initials)->name('Justine Bieber')->generate(); // Output: JB
echo (new Initials('John Christian Doe'))->generate(); // Output: JD
echo (new Initials)->generate('Leonardo'); // Output: LE
echo (new Initials)->length(1)->generate('Camilla'); // Output: C
echo (new Initials)->name('Jens Ølsted')->getUrlfriendlyInitials(); // Output: JO

All you'll have to do is either pass in the name in the constructor like so:

echo new Initials('The Name Here'); // TH

or use the name($name) method, to specify the name.

Supported methods

name($name = 'John Doe')

$initials->name('Albert Magnum')->generate();

length($length = 2)

$initials->name('Albert Magnum')->length(3)->generate();

generate()

This method will output the initials. It's completely optional, you could also just echo out the class as it has a __toString() method.

$initials->name('Albert Magnum')->generate();

getUrlfriendlyInitials()

Will output url-friendly initials (stripping characters like Γ†Γ˜Γ…)

Requirements

  • PHP 5.6, 7.0 or 7.1