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.
composer require poletaew/sms-segment-calculator
use Poletaew\SmsSegmentCalculator\Models\SegmentedMessage;
$segmentedMessage = new SegmentedMessage('Hello World');
echo $segmentedMessage->getRealEncodingName() . PHP_EOL; // "GSM-7"
echo $segmentedMessage->getSegmentsCount(); // "1"
This is the main class exposed by the package
Arguments:
$message
: Body of the SMS$encoding
: Optional: encoding. It can beSmsEncoding
enum value orauto
. Default value:auto
$smartEncoding
: Optional: if smart encoding enabled. Default value:false
Returns the name of the calculated encoding for the message: GSM-7
or UCS-2
Total size of the message in bits (including User Data Header if present)
Total size of the message in bits (excluding User Data Header if present)
Number of segment(s)
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
Number of Unicode scalars
Number of characters
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.
No warranty expressed or implied. Software is as is.