Skip to content

Instantly share code, notes, and snippets.

@MSHADroo
Created February 3, 2020 08:13
Show Gist options
  • Save MSHADroo/b1b1783c1821aa6224dd2f3ae3c8fc8f to your computer and use it in GitHub Desktop.
Save MSHADroo/b1b1783c1821aa6224dd2f3ae3c8fc8f to your computer and use it in GitHub Desktop.
php check persian and english sms length
<?php
function checkSMSLength($text) {
$ucs2 = preg_match('/[^\x00-\x7E]/', $text);
if (!$ucs2){
$text = preg_replace('/([[\]{}~^|\\\\])/', "\\$1",$text);
}
$strLength = mb_strlen($text);
$unitLength = $ucs2 ? 70 : 160;
if ($strLength > $unitLength) {
$unitLength = $ucs2 ? $unitLength - 3 : $unitLength - 7;
}
$count = max(ceil($strLength / $unitLength), 1);
$remain = $unitLength * $count - $strLength;
return [
'count' => $count,
'remain' => $remain
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment