search
Homephp教程php手册php 解析emoji表情 支持微信

php 解析emoji表情 支持微信

Jun 06, 2016 pm 07:38 PM
emojiphpintroduceWeChatsupportexpressionparse

请引入php-emoji 主要方法就是解析但发送还没做好,需要ubb编辑器支持,这个我还会改进 php-emoji //转换得到含emoji表情的代码 注意引入css文件 function parseHtmlemoji ($text) { require_once 'emoji/emoji.php'; $tmpStr = json_encode($text); $tmpStr

请引入php-emoji

主要方法就是解析  但发送还没做好,需要ubb编辑器支持,这个我还会改进 php-emoji
    //转换得到含emoji表情的代码 注意引入css文件
    function parseHtmlemoji ($text)
    {
        require_once 'emoji/emoji.php';
        $tmpStr = json_encode($text);
        $tmpStr = preg_replace("#(\\\ue[0-9a-f]{3})#ie", "addslashes('\\1')", 
        $tmpStr);
        $text = json_decode($tmpStr);
        preg_match_all("#u([0-9a-f]{4})+#iUs", $text, $rs);
        if (empty($rs[1])) {
            return $text;
        }
        foreach ($rs[1] as $v) {
            $test_iphone = '0x' . trim(strtoupper($v));
            $test_iphone = $test_iphone + 0;
            $t = emoji_unified_to_html(
            emoji_softbank_to_unified(utf8_bytes($test_iphone)));
            $text = str_replace("\u$v", $t, $text);
        }
        return $text;
    }
    function utf8_bytes ($cp)
    {
        if ($cp > 0x10000) {
            # 4 bytes
            return chr(0xF0 | (($cp & 0x1C0000) >> 18)) .
             chr(0x80 | (($cp & 0x3F000) >> 12)) .
             chr(0x80 | (($cp & 0xFC0) >> 6)) . chr(0x80 | ($cp & 0x3F));
        } else 
            if ($cp > 0x800) {
                # 3 bytes
                return chr(0xE0 | (($cp & 0xF000) >> 12)) .
                 chr(0x80 | (($cp & 0xFC0) >> 6)) . chr(0x80 | ($cp & 0x3F));
            } else 
                if ($cp > 0x80) {
                    # 2 bytes
                    return chr(0xC0 | (($cp & 0x7C0) >> 6)) .
                     chr(0x80 | ($cp & 0x3F));
                } else {
                    # 1 byte
                    return chr($cp);
                }
    }
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.