Convert string to emojis


/ Published in: HTML
Save to your folder(s)

Simple converter of string with name of few countries and time to proper emoji representation in unicode


Copy this code and paste it in your HTML
  1. function convertNumberToEmoji($cyfra)
  2. {
  3.  
  4. switch ($cyfra) {
  5. case '0':
  6. return "\u{30}\u{FE0F}\u{20E3}";
  7. break;
  8. case '1':
  9. return "\u{31}\u{FE0F}\u{20E3}";
  10. break;
  11. case '2':
  12. return "\u{32}\u{FE0F}\u{20E3}";
  13. break;
  14. case '3':
  15. return "\u{33}\u{FE0F}\u{20E3}";
  16. break;
  17. case '4':
  18. return "\u{34}\u{FE0F}\u{20E3}";
  19. break;
  20. case '5':
  21. return "\u{35}\u{FE0F}\u{20E3}";
  22. break;
  23. case '6':
  24. return "\u{36}\u{FE0F}\u{20E3}";
  25. break;
  26. case '7':
  27. return "\u{37}\u{FE0F}\u{20E3}";
  28. break;
  29. case '8':
  30. return "\u{38}\u{FE0F}\u{20E3}";
  31. break;
  32. case '9':
  33. return "\u{39}\u{FE0F}\u{20E3}";
  34. break;
  35. default:
  36. return " ";
  37. break;
  38. }
  39. }
  40.  
  41. function convertTimeToEmoji($str)
  42. {
  43. # Supported time format {hh}:{mm}
  44. $array = str_split($str,1);
  45. $result=array();
  46. foreach ($array as $char) {
  47. $result[] = convertNumberToEmoji($char);
  48. }
  49. $emojistring = implode("",$result);
  50. return $emojistring;
  51.  
  52. }
  53. function convertTimeToClockIcon($str)
  54. {
  55. # Supported time format {hh}:{mm}
  56. #
  57. $timesbefore=["00:00","00:30","1:00","1:30","2:00","2:30","3:00","3:30","4:00","4:30","5:00","5:30","6:00","6:30","7:00","7:30","8:00","8:30","9:00","9:30","10:00","10:30","11:00","11:30"];
  58. $timesafter =[
  59. "12:00" => "\u{1F55B}",
  60. "12:30" => "\u{1F567}",
  61. "13:00" => "\u{1F550}",
  62. "13:30" => "\u{1F55C}",
  63. "14:00" => "\u{1F551}",
  64. "14:30" => "\u{1F55D}",
  65. "15:00" => "\u{1F552}",
  66. "15:30" => "\u{1F55E}",
  67. "16:00" => "\u{1F553}",
  68. "16:30" => "\u{1F55F}",
  69. "17:00" => "\u{1F554}",
  70. "17:30" => "\u{1F560}",
  71. "18:00" => "\u{1F555}",
  72. "18:30" => "\u{1F561}",
  73. "19:00" => "\u{1F556}",
  74. "19:30" => "\u{1F562}",
  75. "20:00" => "\u{1F557}",
  76. "20:30" => "\u{1F563}",
  77. "21:00" => "\u{1F558}",
  78. "21:30" => "\u{1F564}",
  79. "22:00" => "\u{1F559}",
  80. "22:30" => "\u{1F565}",
  81. "23:00" => "\u{1F55A}",
  82. "23:30" => "\u{1F566}"
  83. ];
  84. if (in_array($str, $timesbefore)) {
  85.  
  86. foreach (array_values($timesbefore) as $i => $value) {
  87. if ($str == $value) {
  88. $allkeys = array_keys($timesafter);
  89. return $timesafter[$allkeys[$i]];
  90. }
  91. }
  92. } else {
  93. if (array_key_exists($str,$timesafter)) {
  94. return $timesafter[$str];
  95. }
  96. }
  97. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.