0

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?

Community
  • 1
  • 1
newbmiao
  • 51
  • 1
  • 11
  • Have you read [this post](http://stackoverflow.com/a/16893103/3424892)? You could do a `mysql_query ('SET NAMES utf8mb4')` before too... are you? The difference between UTF-8 and UTF8mb4 is that mysql "utf-8" does not support 4 byte characters, so they've corrected with UTF8mb4. – lalengua Jun 01 '15 at 00:13
  • possible duplicate of [Using utf8mb4 with php and mysql](http://stackoverflow.com/questions/16893035/using-utf8mb4-with-php-and-mysql) – guido Jun 01 '15 at 00:15
  • i can get the correct char_length in mysql but how to make it in php before i store them in mysql? – newbmiao Jun 01 '15 at 00:38
  • You can get the character length of a UTF-8 string in PHP using `mb_strlen($text, 'UTF-8')`, if that's what you're asking. – Austin Jun 01 '15 at 01:08
  • @ Austin yes,it my fault , php mb_* support utf8*,thk – newbmiao Jun 01 '15 at 01:17

1 Answers1

1
  • js twitter-text-js

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

  • php

    mb_strlen

newbmiao
  • 51
  • 1
  • 11