https://github.com/lasserafn/php-initials
Library to generate initials from a full name. PHP 5.6+
https://github.com/lasserafn/php-initials
initials name php php56 php7
Last synced: 12 months ago
JSON representation
Library to generate initials from a full name. PHP 5.6+
- Host: GitHub
- URL: https://github.com/lasserafn/php-initials
- Owner: LasseRafn
- License: mit
- Created: 2017-02-14T14:39:59.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-08-23T17:07:40.000Z (over 1 year ago)
- Last Synced: 2025-03-27T00:11:35.646Z (about 1 year ago)
- Topics: initials, name, php, php56, php7
- Language: PHP
- Homepage:
- Size: 49.8 KB
- Stars: 41
- Watchers: 1
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Generate initials from names
This is the core of [LasseRafn/php-initial-avatar-generator](http://github.com/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.)
## Installation
You just require using composer and you're good to go!
```bash
composer require lasserafn/php-initials
```
## Usage
As with installation, usage is quite simple. Generating a image is done by running:
```php
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:
```php
echo new Initials('The Name Here'); // TH
```
or use the `name($name)` method, to specify the name.
## Supported methods
### name($name = 'John Doe')
```php
$initials->name('Albert Magnum')->generate();
```
### length($length = 2)
```php
$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.
```php
$initials->name('Albert Magnum')->generate();
```
### getUrlfriendlyInitials()
Will output url-friendly initials (stripping characters like ÆØÅ)
## Requirements
* PHP 5.6, 7.0 or 7.1