public static function unicodeToShortcode($content)
    {
        $replacement = '';
        $encoding = mb_detect_encoding($content);
        $codepoints = array_flip(self::getShortcodes());

        /* Break content along codepoint boundaries */
        $parts = preg_split(
            self::MB_REGEX,
            $content,
            -1,
            PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
        );

        /* Reconstruct content using shortcodes */
        $sequence = [];
        foreach ($parts as $offset => $part) {
            if (preg_match(self::MB_REGEX, $part)) {
                $part = mb_convert_encoding($part, 'UTF-32', $encoding);
                $words = unpack('N*', $part);
                $codepoint = sprintf('%X', reset($words));

                $sequence[] = $codepoint;

                if (isset($codepoints[$codepoint])) {
                    $replacement .= ":$codepoints[$codepoint]:";
                    $sequence = [];
                } else {
                    /* Check multi-codepoint sequence */
                    $multi = implode('-', $sequence);

                    if (isset($codepoints[$multi])) {
                        $replacement .= ":$codepoints[$multi]:";
                        $sequence = [];
                    }
                }
            } else {
                $replacement .= $part;
            }
        }

        return $replacement;
    }
public static function unicodeToShortcode($content)
    {
        $replacement = '';
        $encoding = mb_detect_encoding($content);
        $codepoints = array_flip(self::getShortcodes());

        /* Break content along codepoint boundaries */
        $parts = preg_split(
            self::MB_REGEX,
            $content,
            -1,
            PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
        );

        /* Reconstruct content using shortcodes */
        $sequence = [];
        foreach ($parts as $offset => $part) {
            if (preg_match(self::MB_REGEX, $part)) {
                $part = mb_convert_encoding($part, 'UTF-32', $encoding);
                $words = unpack('N*', $part);
                $codepoint = sprintf('%X', reset($words));

                $sequence[] = $codepoint;

                if (isset($codepoints[$codepoint])) {
                    $replacement .= ":$codepoints[$codepoint]:";
                    $sequence = [];
                } else {
                    /* Check multi-codepoint sequence */
                    $multi = implode('-', $sequence);

                    if (isset($codepoints[$multi])) {
                        $replacement .= ":$codepoints[$multi]:";
                        $sequence = [];
                    }
                }
            } else {
                $replacement .= $part;
            }
        }

        return $replacement;
    }
public static function unicodeToShortcode ( $ content ) { $ replacement = '' ; $ encoding = mb_detect_encoding ( $ content ) ; $ codepoints = array_flip ( self :: getShortcodes ( ) ) ; /* Break content along codepoint boundaries */ $ parts = preg_split ( self :: MB_REGEX , $ content , - 1 , PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ) ; /* Reconstruct content using shortcodes */ $ sequence = [ ] ; foreach ( $ parts as $ offset => $ part ) { if ( preg_match ( self :: MB_REGEX , $ part ) ) { $ part = mb_convert_encoding ( $ part , 'UTF-32' , $ encoding ) ; $ words = unpack ( 'N*' , $ part ) ; $ codepoint = sprintf ( '%X' , reset ( $ words ) ) ; $ sequence [ ] = $ codepoint ; if ( isset ( $ codepoints [ $ codepoint ] ) ) { $ replacement .= ":$codepoints[$codepoint]:" ; $ sequence = [ ] ; } else { /* Check multi-codepoint sequence */ $ multi = implode ( '-' , $ sequence ) ; if ( isset ( $ codepoints [ $ multi ] ) ) { $ replacement .= ":$codepoints[$multi]:" ; $ sequence = [ ] ; } } } else { $ replacement .= $ part ; } } return $ replacement ; }
Converts unicode codepoints to plaintext shortcodes.

@param string $content
@return string
Converts unicode codepoints to plaintext shortcodes .