PHPackages                             omar-haris/card-name-fit - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. omar-haris/card-name-fit

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

omar-haris/card-name-fit
========================

PHP library to squeeze Arabic or English personal names to a fixed length for ID, bank or payment cards.

v1.0.0(1y ago)0141MITPHPPHP ^8.3CI passing

Since Apr 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/omar-haris/card-name-fit)[ Packagist](https://packagist.org/packages/omar-haris/card-name-fit)[ Docs](https://github.com/omar-haris/card-name-fit)[ RSS](/packages/omar-haris-card-name-fit/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Card Name Fit
=============

[](#card-name-fit)

A simple PHP library that solves the headache of fitting names on cards and badges. If you've ever struggled with names that are too long for credit cards, ID badges, or passport printing, this is your solution.

[![Latest Version on Packagist](https://camo.githubusercontent.com/0d29d33896ca1d5a573f2551b6a09c94221c3fb026b1cadd2285f3aa063c90af/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f6d61722d68617269732f636172642d6e616d652d6669742e737667)](https://packagist.org/packages/omar-haris/card-name-fit)[![Tests](https://github.com/omar-haris/card-name-fit/actions/workflows/tests.yml/badge.svg)](https://github.com/omar-haris/card-name-fit/actions/workflows/tests.yml)[![PHP Version](https://camo.githubusercontent.com/00332863d98eafd199ff8faaf886c7059e467c5f469e31f862afd6be638c93aa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6f6d61722d68617269732f636172642d6e616d652d6669742e737667)](https://packagist.org/packages/omar-haris/card-name-fit)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![Total Downloads](https://camo.githubusercontent.com/f384f92925a489070400278fcd12f957f8144d7427940124457d171720eee658/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f6d61722d68617269732f636172642d6e616d652d6669742e737667)](https://packagist.org/packages/omar-haris/card-name-fit)

Why This Library?
-----------------

[](#why-this-library)

We've all seen ID cards with awkwardly truncated names or ridiculously small fonts trying to fit long names. This library fixes that problem with intelligent name formatting for fixed-width spaces.

It's especially useful for:

- Card printing (credit, debit, ID, membership)
- Name badges and tags
- Passports and government IDs
- Any system with character limits for names

Key Features
------------

[](#key-features)

- **Smart formatting** that preserves readability
- **Handles both English and Arabic** names with different strategies
- **Adjustable character limits** to match your exact requirements
- **UTF-8 support** for international names
- **No external dependencies** besides PHP's mbstring

Installation
------------

[](#installation)

Just run:

```
composer require omar-haris/card-name-fit
```

Basic Usage
-----------

[](#basic-usage)

```
use CardNameFit\NameFormatter;

// Create a formatter with 20-character limit
$formatter = new NameFormatter(20);

// Format some names
echo $formatter->format('John William Smith');             // "John William Smith"
echo $formatter->format('John William Alexander Smith');   // "John William Smith"

// Works with Arabic names too
echo $formatter->format('محمد عبد الرحمن العبد الله');     // "محمد عبد الرحمن"
```

Formatting Strategies
---------------------

[](#formatting-strategies)

### For English Names

[](#for-english-names)

The library offers two approaches:

#### 1. GREEDY (default)

[](#1-greedy-default)

Keeps full middle names when possible, drops them when needed. People generally prefer seeing their complete names rather than initials.

```
// With 20 character limit
$formatter = new NameFormatter(20, NameFormatter::ENGLISH_GREEDY);

echo $formatter->format('John Smith');                   // "John Smith"
echo $formatter->format('John William Smith');           // "John William Smith"
echo $formatter->format('John William Alexander Smith'); // "John William Smith"
                                                         // (drops "Alexander")
```

#### 2. DENSE

[](#2-dense)

Ensures every name part appears, at least as an initial. Better when all name components must be represented.

```
// With 20 character limit
$formatter = new NameFormatter(20, NameFormatter::ENGLISH_DENSE);

echo $formatter->format('John William Alexander Smith'); // "John W. A. Smith"
                                                         // (includes all parts)
```

### For Arabic Names

[](#for-arabic-names)

Arabic names use a simple left-to-right approach, preserving whole words since initials don't make sense in Arabic.

```
$formatter = new NameFormatter(25);

echo $formatter->format('محمد عبد الرحمن العبد الله'); // "محمد عبد الرحمن"
```

Edge Cases Handled
------------------

[](#edge-cases-handled)

### Very Long Names

[](#very-long-names)

The library handles unusually long names gracefully:

```
$formatter = new NameFormatter(20);

// Long last name
echo $formatter->format('John Wolfeschlegelsteinhausenbergerdorff');
// "John Wolfeschlegelst"
```

### Whitespace Cleanup

[](#whitespace-cleanup)

No need to worry about extra spaces or inconsistent formatting:

```
$formatter = new NameFormatter(20);
echo $formatter->format('  John   William   Smith  '); // "John William Smith"
```

Configuration
-------------

[](#configuration)

```
/**
 * @param int    $maxLength   Maximum allowed characters (≥ 1)
 * @param string $englishMode Strategy: ENGLISH_GREEDY or ENGLISH_DENSE
 * @param string $encoding    Character encoding (default: UTF-8)
 */
public function __construct(
    int    $maxLength   = 35,
    string $englishMode = self::ENGLISH_GREEDY,
    string $encoding    = 'UTF-8'
)
```

Security &amp; Compliance
-------------------------

[](#security--compliance)

This library only formats text - it doesn't store or transmit any personal data. It's designed with:

- GDPR considerations (no data retention)
- PCI DSS compatibility (no cardholder data storage)

Requirements
------------

[](#requirements)

- PHP 8.3+
- mbstring extension

License
-------

[](#license)

MIT License. See the [LICENSE](LICENSE.md) file.

Credits
-------

[](#credits)

- [Omar Haris](https://github.com/omar-haris)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance48

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

380d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c02cfd46d931e216c0159695403fd1c4513d2a3a5e74afe292f0f07d9f76ec00?d=identicon)[omar-haris](/maintainers/omar-haris)

---

Top Contributors

[![omar-haris](https://avatars.githubusercontent.com/u/16119345?v=4)](https://github.com/omar-haris "omar-haris (4 commits)")

---

Tags

arabicbankcredit-cardenglishmastercardnameshortenervisaPHP Libraryvisacredit-carddebit cardID Cardbank-cardidentity cardpayment-cardcard-namename-fitname-formattername-truncatename-shortenname-compressarabic-nameslatin-namescharacter-limitcard-printingsecurity-card

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/omar-haris-card-name-fit/health.svg)

```
[![Health](https://phpackages.com/badges/omar-haris-card-name-fit/health.svg)](https://phpackages.com/packages/omar-haris-card-name-fit)
```

###  Alternatives

[lodash-php/lodash-php

A port of Lodash to PHP

527719.0k5](/packages/lodash-php-lodash-php)[marvinlabs/laravel-luhn

Luhn algorithm for Laravel

108409.7k](/packages/marvinlabs-laravel-luhn)[ofcold/identity-card

A simple proof of identity card of the people's Republic of China.

18839.6k](/packages/ofcold-identity-card)[niiknow/bayes

a machine learning lib

6950.0k](/packages/niiknow-bayes)[amirezaeb/heroqr

A Powerful QR Code Management Library For PHP

9510.3k](/packages/amirezaeb-heroqr)[rapidwebltd/php-uk-bank-holidays

This library enables developers to easily retrieve UK Bank Holiday details. Holidays can be retrieved for England &amp; Wales, Scotland, and Northern Ireland. Information about these holidays can optionally be restricted by month or date.

12405.5k](/packages/rapidwebltd-php-uk-bank-holidays)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
