Search code examples
javascriptphputf8mb4

how to get character's length which encoding with utf8mb4 in php and js


I use mysql which support utf8mb4 to store emoji, but in the php or js side, I can not get the correct length of them which is my function of textarea input maxlength.

as so far I know, utf8mb4 is not support by php or web side. Does anybody know how to make it?

i just get a js to solve it in js side ,which is supported by twitter! see twitter-text-js

but how to make it in php side, I don't find a new twitter-text-php? I also find this answer, but how to use it?


Solution

    • js twitter-text-js

      var tweet = "👌h饿1"; var remainingCharacters = twttr.txt.getTweetLength(tweet);

    • php

      mb_strlen