Skip to content

Instantly share code, notes, and snippets.

@mcsepes
Last active December 27, 2022 17:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcsepes/a2f1f6d383a6ac1ef558a9b0407ec1b9 to your computer and use it in GitHub Desktop.
Save mcsepes/a2f1f6d383a6ac1ef558a9b0407ec1b9 to your computer and use it in GitHub Desktop.
Check if string has emojis PHP. DEPRECATED. USE AT YOUR OWN RISK
<?php
// DEPRECATED. USE AT YOUR OWN RISK
function isStringHasEmojis($string)
{
$emojis_regex =
'/[\x{0080}-\x{02AF}'
.'\x{0300}-\x{03FF}'
.'\x{0600}-\x{06FF}'
.'\x{0C00}-\x{0C7F}'
.'\x{1DC0}-\x{1DFF}'
.'\x{1E00}-\x{1EFF}'
.'\x{2000}-\x{209F}'
.'\x{20D0}-\x{214F}'
.'\x{2190}-\x{23FF}'
.'\x{2460}-\x{25FF}'
.'\x{2600}-\x{27EF}'
.'\x{2900}-\x{29FF}'
.'\x{2B00}-\x{2BFF}'
.'\x{2C60}-\x{2C7F}'
.'\x{2E00}-\x{2E7F}'
.'\x{3000}-\x{303F}'
.'\x{A490}-\x{A4CF}'
.'\x{E000}-\x{F8FF}'
.'\x{FE00}-\x{FE0F}'
.'\x{FE30}-\x{FE4F}'
.'\x{1F000}-\x{1F02F}'
.'\x{1F0A0}-\x{1F0FF}'
.'\x{1F100}-\x{1F64F}'
.'\x{1F680}-\x{1F6FF}'
.'\x{1F910}-\x{1F96B}'
.'\x{1F980}-\x{1F9E0}]/u';
preg_match($emojis_regex, $string, $matches);
return !empty($matches);
}
var_dump(isStringHasEmojis('qwerty_йцукен')); // false
var_dump(isStringHasEmojis('qwerty🐈йцукен')); // true
@oliveratgithub
Copy link

Thanks, wors like a charm! 👌

@onassar
Copy link

onassar commented May 13, 2022

Thanks!

@btrazzini
Copy link

@riot26 sorry, but the string "São Paulo" (pt-BR 🇧🇷) returns true

var_dump(isStringHasEmojis('São Paulo')); // true

@adevesa
Copy link

adevesa commented Nov 15, 2022

Emojis that don't work:
🥳 🥰 🥲 🥵 🥶 🥴 🥺 🥱 🧡 🤎 🤍 🤌 🤏 🫵 🫀 🫁 🥷 🫂 🪶 🪲 🪳 🪰 🪱 🪴 🪴 🪴 🥭 🫐 🫒 🫑 🥬 🫑 🫓 🥯 🫔 🫕 🥮 🫖 🧭 🧱 🪨 🪵 🪐 🧨 🧧 🪀 🪁 🪄 🧿 🪄 🧩 🧸 🪅 🪆 🪆 🧵 🪡 🧶 🪢 🥽 🥼 🧣 🧤 🧥 🧦 🥻 🩱 🩲 🩳 🩴 🥾 🥿 🩰 🧢 🪖 🪗 🪕 🪘 🪫 🧮 🪔 🪙 🧾 🪓 🪃 🪚 🪛 🪝 🧰 🧲 🪜 🧪 🧫 🧬 🩸 🩹 🩼 🩺 🩻 🪞 🪟 🪑 🪠 🪤 🪒 🧴 🧷 🧹 🧺 🧻 🪣 🧼 🫧 🪥 🧽 🧯 🪦 🪧 🪪 🟰 ㊗ ㊙ 🟠 🟡 🟢 🟣 🟤 🟥 🟧 🟨 🟩 🟦 🟪 🟫

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