diff --git a/SMSCounter.php b/SMSCounter.php index 13a12e3..3063618 100644 --- a/SMSCounter.php +++ b/SMSCounter.php @@ -342,14 +342,20 @@ public function utf8ToUnicode($str) } if ($thisValue >= 128) { - if (count($values) == 0) { - $lookingFor = ($thisValue < 224) ? 2 : 3; + if (count($values) === 0) { + $lookingFor = 2; + + if ($thisValue >= 240) { + $lookingFor = 4; + } elseif ($thisValue >= 224) { + $lookingFor = 3; + } } $values[] = $thisValue; - if (count($values) == $lookingFor) { - $number = ($lookingFor == 3) ? + if (count($values) === $lookingFor) { + $number = ($lookingFor === 3) ? (($values[0] % 16) * 4096) + (($values[1] % 64) * 64) + ($values[2] % 64) : (($values[0] % 32) * 64) + ($values[1] % 64); diff --git a/Tests/SMSCounterTest.php b/Tests/SMSCounterTest.php index 93695ca..242c2d8 100755 --- a/Tests/SMSCounterTest.php +++ b/Tests/SMSCounterTest.php @@ -180,6 +180,23 @@ public function testUnicode() $this->assertEquals($expected, $count); } + public function testUnicodeEmoji() + { + $text = '😎😎'; + + $smsCounter = new SMSCounter(); + $count = $smsCounter->count($text); + + $expected = new \stdClass(); + $expected->encoding = SMSCounter::UTF16; + $expected->length = 2; + $expected->per_message = 70; + $expected->remaining = 68; + $expected->messages = 1; + + $this->assertEquals($expected, $count); + } + public function testRemoveNonGSMChars() { $text = 'áno-unicode-remaining` ñ';