PHPackages                             poletaew/sms-segment-calculator - 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. poletaew/sms-segment-calculator

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

poletaew/sms-segment-calculator
===============================

PHP-based tool to calculate and display SMS segmentation data for a given message body

1.0.0(2y ago)04.3k↑44.8%1MITPHPPHP ^8.1

Since May 22Pushed 2y agoCompare

[ Source](https://github.com/poletaew/sms-segment-calculator)[ Packagist](https://packagist.org/packages/poletaew/sms-segment-calculator)[ RSS](/packages/poletaew-sms-segment-calculator/feed)WikiDiscussions main Synced 2d ago

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

SMS Segment Calculator
======================

[](#sms-segment-calculator)

A PHP library that enables you to calculate the message segments used for sending a message on the GSM network. A port of [Twillio's Segment Calculator](https://github.com/TwilioDevEd/message-segment-calculator).

Usage
-----

[](#usage)

### Installation

[](#installation)

```
composer require poletaew/sms-segment-calculator
```

### Sample usage

[](#sample-usage)

```
use Poletaew\SmsSegmentCalculator\Models\SegmentedMessage;

$segmentedMessage = new SegmentedMessage('Hello World');

echo $segmentedMessage->getRealEncodingName() . PHP_EOL; // "GSM-7"
echo $segmentedMessage->getSegmentsCount(); // "1"
```

Documentation
-------------

[](#documentation)

### `SegmentedMessage` class

[](#segmentedmessage-class)

This is the main class exposed by the package

#### [`__construct($message, $encoding, $smartEncoding)`](https://github.com/poletaew/sms-segment-calculator/blob/bbde70b37ce18def7649a3d8330b393d0e3af8e7/src/Models/SegmentedMessage.php#L31C21-L31C117)

[](#__constructmessage-encoding-smartencoding)

Arguments:

- `$message`: Body of the SMS
- `$encoding`: Optional: encoding. It can be `SmsEncoding` enum value or `auto`. Default value: `auto`
- `$smartEncoding`: Optional: if smart encoding enabled. Default value: `false`

#### [`getRealEncodingName()`](https://github.com/poletaew/sms-segment-calculator/blob/bbde70b37ce18def7649a3d8330b393d0e3af8e7/src/Models/SegmentedMessage.php#L67)

[](#getrealencodingname)

Returns the name of the calculated encoding for the message: `GSM-7` or `UCS-2`

#### [`getTotalSize()`](https://github.com/poletaew/sms-segment-calculator/blob/bbde70b37ce18def7649a3d8330b393d0e3af8e7/src/Models/SegmentedMessage.php#L72)

[](#gettotalsize)

Total size of the message in bits (including User Data Header if present)

#### [`getMessageSize()`](https://github.com/poletaew/sms-segment-calculator/blob/bbde70b37ce18def7649a3d8330b393d0e3af8e7/src/Models/SegmentedMessage.php#L77C21-L77C35)

[](#getmessagesize)

Total size of the message in bits (excluding User Data Header if present)

#### [`getSegmentsCount()`](https://github.com/poletaew/sms-segment-calculator/blob/bbde70b37ce18def7649a3d8330b393d0e3af8e7/src/Models/SegmentedMessage.php#L82C21-L82C37)

[](#getsegmentscount)

Number of segment(s)

#### [`getNonGsmCharacters()`](https://github.com/poletaew/sms-segment-calculator/blob/bbde70b37ce18def7649a3d8330b393d0e3af8e7/src/Models/SegmentedMessage.php#L87C21-L87C40)

[](#getnongsmcharacters)

Return an array with the non GSM-7 characters in the body. It can be used to replace character and reduce the number of segments

#### [`getNumberOfUnicodeScalars()`](https://github.com/poletaew/sms-segment-calculator/blob/bbde70b37ce18def7649a3d8330b393d0e3af8e7/src/Models/SegmentedMessage.php#L92C21-L92C46)

[](#getnumberofunicodescalars)

Number of Unicode scalars

#### [`getNumberOfCharacters()`](https://github.com/poletaew/sms-segment-calculator/blob/bbde70b37ce18def7649a3d8330b393d0e3af8e7/src/Models/SegmentedMessage.php#L97C21-L97C42)

[](#getnumberofcharacters)

Number of characters

Contributing
------------

[](#contributing)

This code is open source and welcomes contributions.

The source code for the library is all contained in the `src` folder. Before submitting a PR run Unit test in the directory `test/Unit` and make sure all tests pass.

License
-------

[](#license)

[MIT](http://www.opensource.org/licenses/mit-license.html)

Disclaimer
----------

[](#disclaimer)

No warranty expressed or implied. Software is as is.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

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

773d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2600649?v=4)[Michael Poletaew](/maintainers/poletaew)[@poletaew](https://github.com/poletaew)

---

Top Contributors

[![poletaew](https://avatars.githubusercontent.com/u/2600649?v=4)](https://github.com/poletaew "poletaew (8 commits)")[![l-alexandrov](https://avatars.githubusercontent.com/u/14351652?v=4)](https://github.com/l-alexandrov "l-alexandrov (6 commits)")[![viktordanov](https://avatars.githubusercontent.com/u/7188510?v=4)](https://github.com/viktordanov "viktordanov (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/poletaew-sms-segment-calculator/health.svg)

```
[![Health](https://phpackages.com/badges/poletaew-sms-segment-calculator/health.svg)](https://phpackages.com/packages/poletaew-sms-segment-calculator)
```

PHPackages © 2026

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