dimanche 10 février 2019

Check if ONLY emojis are placed as json in a php-string

This simple php-function allows me to check, whether a string contains an emoji (in json-format).

function has_emojis( $string ) {

    preg_match( '/[\x{1F600}-\x{1F64F}]/u', $string, $matches_emo );

    return !empty( $matches_emo[0] ) ? true : false;

}

So far so good.


But I'd like to check, if the string contains ONLY emoji(s). For example:

\ud83d\ude07 = true

\ud83d\ude07\ud83d\ude4c = true

\ud83d\ude07 \ud83d\ude4c = false

\ud83d\ude07 text = false

text = false


Could somebody please help?

Aucun commentaire:

Enregistrer un commentaire