diff options
author | Antoine Descamps <antoine@antoinedescamps.fr> | 2016-11-16 18:54:57 +0100 |
---|---|---|
committer | Wouter van Oortmerssen <wvo@google.com> | 2016-11-16 09:54:57 -0800 |
commit | dbecdf209de88ed0910ba602d326d33b5aefed93 (patch) | |
tree | b3e5052f9464af367cb0ce7945fd043d98e7a757 /php | |
parent | c05803bf9683f3e8dff76bf85d6030ec00823564 (diff) | |
download | flatbuffers-dbecdf209de88ed0910ba602d326d33b5aefed93.tar.gz flatbuffers-dbecdf209de88ed0910ba602d326d33b5aefed93.tar.bz2 flatbuffers-dbecdf209de88ed0910ba602d326d33b5aefed93.zip |
[PHP] Use mb_detect_encoding when available (#3952)
I've faced an issue where I want to serialize UTF-8 emojis and FlatBufferBuilder::is_utf8 would return false on them.
I was not able to add the corresponding hexadecimal code because I don't understand how the whole thing works but what i've done is using the `mb_detect_encoding` function which handles correctly all supposed UTF-8 characters.
Diffstat (limited to 'php')
-rw-r--r-- | php/FlatbufferBuilder.php | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/php/FlatbufferBuilder.php b/php/FlatbufferBuilder.php index 6f0ee483..5c18bf46 100644 --- a/php/FlatbufferBuilder.php +++ b/php/FlatbufferBuilder.php @@ -593,6 +593,10 @@ class FlatbufferBuilder protected function is_utf8($bytes) { + if (function_exists('mb_detect_encoding')) { + return (bool) mb_detect_encoding($bytes, 'UTF-8', true); + } + $len = strlen($bytes); if ($len < 1) { /* NOTE: always return 1 when passed string is null */ |