PHPackages                             benmorel/gsm-charset-converter - 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. benmorel/gsm-charset-converter

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

benmorel/gsm-charset-converter
==============================

Converts GSM 03.38 strings to and from UTF-8

0.3.2(1mo ago)16499.6k↓25.1%10[1 issues](https://github.com/BenMorel/GsmCharsetConverter/issues)[1 PRs](https://github.com/BenMorel/GsmCharsetConverter/pulls)MITPHPPHP ^7.4 || ^8.0CI passing

Since Nov 23Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/BenMorel/GsmCharsetConverter)[ Packagist](https://packagist.org/packages/benmorel/gsm-charset-converter)[ GitHub Sponsors](https://github.com/BenMorel)[ RSS](/packages/benmorel-gsm-charset-converter/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (6)Versions (11)Used By (0)

GSM Charset Converter
=====================

[](#gsm-charset-converter)

A PHP library to convert GSM 03.38, the charset used for SMS messaging, to and from UTF-8.

[![Build Status](https://github.com/BenMorel/GsmCharsetConverter/workflows/CI/badge.svg)](https://github.com/BenMorel/GsmCharsetConverter/actions)[![Coverage Status](https://camo.githubusercontent.com/c148643f54469dc39117079a8ed3c776e7e3d7837cedce4bfdfaea3a15344487/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f42656e4d6f72656c2f47736d43686172736574436f6e7665727465722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/BenMorel/GsmCharsetConverter?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/cd9135333a13fb4c40ceb226f527ecff79f8e33b03eb637e398b298ff5c08dc2/68747470733a2f2f706f7365722e707567782e6f72672f62656e6d6f72656c2f67736d2d636861727365742d636f6e7665727465722f762f737461626c65)](https://packagist.org/packages/benmorel/gsm-charset-converter)[![Total Downloads](https://camo.githubusercontent.com/3a29099b54925baadcebe69ec9db9848c08ab33a1e962ee30955527acb88b615/68747470733a2f2f706f7365722e707567782e6f72672f62656e6d6f72656c2f67736d2d636861727365742d636f6e7665727465722f646f776e6c6f616473)](https://packagist.org/packages/benmorel/gsm-charset-converter)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](http://opensource.org/licenses/MIT)

This library is well tested. The character maps used have been cross-checked against multiple sources, and when in doubt, a test has been performed on a real SMS gateway.

The library offers optional transliteration: unsupported characters can be replaced with a close variant. For example, the `ë` character can be replaced with `e`.

Known limitations:

- Only the default alphabet and extension table are supported at the moment; this is the alphabet that must be supported by every device and network element according to the standard. [Other alphabets exist](https://en.wikipedia.org/wiki/GSM_03.38#National_language_shift_tables) but this project does not currently aim to support them.
- Transliteration may not be available for all characters that could have a close equivalent in the GSM charset; this library supports transliteration of LATIN1 chars and several other languages. If you feel like another UTF-8 character could be transliterated, please [open an issue](https://github.com/BenMorel/GsmCharsetConverter/issues)!

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

[](#installation)

This library is installable via [Composer](https://getcomposer.org/):

```
composer require benmorel/gsm-charset-converter
```

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

[](#requirements)

This library requires PHP &gt;= 7.4, and the `mbstring` extension.

Project status &amp; release process
------------------------------------

[](#project-status--release-process)

This library is under development.

The current releases are numbered `0.x.y`. When a non-breaking change is introduced (adding new methods, optimizing existing code, etc.), `y` is incremented.

**When a breaking change is introduced, a new `0.x` version cycle is always started.**

It is therefore safe to lock your project to a given release cycle, such as `0.3.*`.

If you need to upgrade to a newer release cycle, check the [release history](https://github.com/BenMorel/GsmCharsetConverter/releases)for a list of changes introduced by each further `0.x.0` version.

Usage
-----

[](#usage)

### Converting GSM 03.38 strings to UTF-8

[](#converting-gsm-0338-strings-to-utf-8)

The `convertGsmToUtf8()` method takes one parameter:

```
use BenMorel\GsmCharsetConverter\Converter;

$converter = new Converter();
$utf8 = $converter->convertGsmToUtf8('...');
```

The input string must be a valid GSM 03.38 string, or an `InvalidArgumentException` is thrown. **The input string is expected to be unpacked**: 7-bit chars in 8-bit bytes with a leading zero bit, just like ASCII chars.

### Converting UTF-8 strings to GSM 03.38

[](#converting-utf-8-strings-to-gsm-0338)

The `convertUtf8ToGsm()` method accepts 3 parameters:

- a valid UTF-8 input string;
- whether or not to attempt to transliterate incompatible chars;
- an optional string to replace unknown characters with.

If the input string is not valid UTF-8, an `InvalidArgumentException` is thrown.

The output is an unpacked GSM 03.38 string.

#### Without transliteration

[](#without-transliteration)

```
$gsm = $converter->convertUtf8ToGsm('Helló', false, '?'); // Hell?

```

If the third parameter is not provided, and the string contains characters incompatible with GSM 03.38, an `InvalidArgumentException` is thrown.

#### With transliteration

[](#with-transliteration)

```
$gsm = $converter->convertUtf8ToGsm('Helló', true, '?'); // Hello
```

If the third parameter is not provided, and the string contains characters incompatible with GSM 03.38 and not transliterable, an `InvalidArgumentException` is thrown.

### Cleaning up UTF-8 strings to ensure that a message is sent in the GSM charset

[](#cleaning-up-utf-8-strings-to-ensure-that-a-message-is-sent-in-the-gsm-charset)

Nowadays, most online SMS gateways accept UTF-8 as input; however, some of them do not provide a way to force a message to be sent in the GSM charset.

As a result, you may end up with extra charges caused by your SMS being sent in Unicode (UCS-2) format, causing the segmentation of messages in multiple parts, just because your SMS message contains an unforeseen accented character or emoji.

The library provides a method, `cleanUpUtf8String()`, that prevents these bad surprises, by returning a UTF-8 string that contains only characters that can be safely converted to the GSM charset.

This method accepts the same parameters as `convertUtf8ToGsm()`:

```
$utf8 = $converter->cleanUpUtf8String('Helló', false, '?'); // Hell?
$utf8 = $converter->cleanUpUtf8String('Helló', true, '?'); // Hello
```

### Packing 7-bit strings into 8-bit binary strings

[](#packing-7-bit-strings-into-8-bit-binary-strings)

To fit 160 7-bit characters into a 140 bytes SMS, the characters have to be packed into a binary, 8-bit string. The `Packer` class provides functionality to pack and unpack strings in this format:

```
use BenMorel\GsmCharsetConverter\Packer;

$packer = new Packer();
$packed = $packer->pack('ABC'); // the binary string 41E110
$string = $packer->unpack("\x41\xE1\x10"); // ABC
```

Note that `pack()` throws an `InvalidArgumentException` if the input string contains 8-bit chars (i.e. chars with the leading bit set).

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance91

Actively maintained with recent releases

Popularity47

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 90% 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

Every ~309 days

Recently: every ~397 days

Total

10

Last Release

39d ago

PHP version history (3 changes)0.1.0PHP &gt;=7.1

0.2.0PHP ^7.2 || ^8.0

0.3.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/57189121968030f0770811b461cc92f9c19c08f5c4767292f2ede48b7277cfad?d=identicon)[BenMorel](/maintainers/BenMorel)

---

Top Contributors

[![BenMorel](https://avatars.githubusercontent.com/u/1952838?v=4)](https://github.com/BenMorel "BenMorel (54 commits)")[![nrbrttth](https://avatars.githubusercontent.com/u/23727847?v=4)](https://github.com/nrbrttth "nrbrttth (2 commits)")[![black-viking](https://avatars.githubusercontent.com/u/5479576?v=4)](https://github.com/black-viking "black-viking (1 commits)")[![crebier-corentin](https://avatars.githubusercontent.com/u/17709887?v=4)](https://github.com/crebier-corentin "crebier-corentin (1 commits)")[![neovmt](https://avatars.githubusercontent.com/u/2440601?v=4)](https://github.com/neovmt "neovmt (1 commits)")[![stollr](https://avatars.githubusercontent.com/u/1118790?v=4)](https://github.com/stollr "stollr (1 commits)")

---

Tags

smsgsmGSM 03.38

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/benmorel-gsm-charset-converter/health.svg)

```
[![Health](https://phpackages.com/badges/benmorel-gsm-charset-converter/health.svg)](https://phpackages.com/packages/benmorel-gsm-charset-converter)
```

###  Alternatives

[php-smpp/php-smpp

PHP-based SMPP client lib

236206.3k8](/packages/php-smpp-php-smpp)[instasent/sms-counter-php

SMS Counter PHP Class Library which detects encoding of an SMS message text, counts the characters as per the encoding and gives page limit information.

491.5M4](/packages/instasent-sms-counter-php)[alexandr-mironov/php-smpp

PHP SMPP client lib, fork of onlinecity/php-smpp

5075.0k](/packages/alexandr-mironov-php-smpp)[alexandr-mironov/php8-smpp

PHP8 SMPP client lib, based on fork of alexandr-mironov/php-smpp which is fork of onlinecity/php-smpp

1229.1k](/packages/alexandr-mironov-php8-smpp)[php8-smpp/php8-smpp

PHP8 SMPP client lib, based on fork of alexandr-mironov/php-smpp which is fork of onlinecity/php-smpp

1215.0k](/packages/php8-smpp-php8-smpp)[matthewbdaly/sms-client

A generic SMS client library. Supports multiple swappable drivers.

2294.3k2](/packages/matthewbdaly-sms-client)

PHPackages © 2026

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