Skip to content

Instantly share code, notes, and snippets.

@kevineduardo
Created April 11, 2023 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevineduardo/130274eb79b22ecaaa5aac222ba526cf to your computer and use it in GitHub Desktop.
Save kevineduardo/130274eb79b22ecaaa5aac222ba526cf to your computer and use it in GitHub Desktop.
PHP Int Number to Emoji Script
  <?php

  function number_to_emoji($number) {
    $digits = str_split($number);
    $emoji = "";
    foreach ($digits as $digit) {
      $emoji .= emoji_digit($digit);
    }
    return $emoji;
  }

  function emoji_digit($digit) {
    $digit_emojis = array(
      '0' => '&#x0030;&#x20E3;', // 0️⃣
      '1' => '&#x0031;&#x20E3;', // 1️⃣
      '2' => '&#x0032;&#x20E3;', // 2️⃣
      '3' => '&#x0033;&#x20E3;', // 3️⃣
      '4' => '&#x0034;&#x20E3;', // 4️⃣
      '5' => '&#x0035;&#x20E3;', // 5️⃣
      '6' => '&#x0036;&#x20E3;', // 6️⃣
      '7' => '&#x0037;&#x20E3;', // 7️⃣
      '8' => '&#x0038;&#x20E3;', // 8️⃣
      '9' => '&#x0039;&#x20E3;', // 9️⃣
    );
    return $digit_emojis[$digit];
  }

  // Teste
  echo number_to_emoji(123);

  ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment