EmojiHelper.php 676 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace addons\WangDianTong\common\helper;
  3. class EmojiHelper
  4. {
  5. /**
  6. * @param string $str
  7. * @return string
  8. */
  9. public static function convert(string $str): string
  10. {
  11. $mbLen = mb_strlen($str);
  12. if ($mbLen > 0) {
  13. $strArr = [];
  14. for ($i = 0; $i < $mbLen; $i++) {
  15. $mbSubstr = mb_substr($str, $i, 1, 'utf-8');
  16. if (strlen($mbSubstr) >= 4) {
  17. // $strArr[] = '*';
  18. } else {
  19. $strArr[] = $mbSubstr;
  20. }
  21. }
  22. if (!empty($strArr)) return implode('', $strArr);
  23. }
  24. return '';
  25. }
  26. }