Table of Contents
php中utf-8转unicode,phputf-8转unicode
Home Backend Development PHP Tutorial Convert utf-8 to unicode in php, phputf-8 to unicode_PHP tutorial

Convert utf-8 to unicode in php, phputf-8 to unicode_PHP tutorial

Jul 13, 2016 am 10:11 AM
escape character

php中utf-8转unicode,phputf-8转unicode

<span>public</span> <span>function</span> utf8_unicode(<span>$str</span><span>) {
    </span><span>$unicode</span> = <span>array</span><span>();
    </span><span>$values</span> = <span>array</span><span>();
    </span><span>$lookingFor</span> = 1<span>;

    </span><span>for</span> (<span>$i</span> = 0; <span>$i</span> < <span>strlen</span>( <span>$str</span> ); <span>$i</span>++<span> ) {
        </span><span>$thisValue</span> = <span>ord</span>( <span>$str</span>[ <span>$i</span><span> ] );
        </span><span>if</span> ( <span>$thisValue</span> < <span>ord</span>('A'<span>) ) {
            </span><span>//</span><span> exclude 0-9</span>
            <span>if</span> (<span>$thisValue</span> >= <span>ord</span>('0') && <span>$thisValue</span> <= <span>ord</span>('9'<span>)) {
                 </span><span>//</span><span> number</span>
                 <span>$unicode</span>[] = <span>chr</span>(<span>$thisValue</span><span>);
            }
            </span><span>else</span><span> {
                 </span><span>$unicode</span>[] = '%'.<span>dechex</span>(<span>$thisValue</span><span>);
            }
        } </span><span>else</span><span> {
            </span><span>if</span> ( <span>$thisValue</span> < 128<span>) {
                </span><span>$unicode</span>[] = <span>$str</span>[ <span>$i</span><span> ];
            } </span><span>else</span><span> {
                </span><span>if</span> ( <span>count</span>( <span>$values</span> ) == 0<span> ) {
                    </span><span>$lookingFor</span> = ( <span>$thisValue</span> < 224 ) ? 2 : 3<span>;
                }
                </span><span>$values</span>[] = <span>$thisValue</span><span>;
                </span><span>if</span> ( <span>count</span>( <span>$values</span> ) == <span>$lookingFor</span><span> ) {
                    </span><span>$number</span> = ( <span>$lookingFor</span> == 3 ) ?<span>
                        ( ( </span><span>$values</span>[0] % 16 ) * 4096 ) + ( ( <span>$values</span>[1] % 64 ) * 64 ) + ( <span>$values</span>[2] % 64 ):<span>
                        ( ( </span><span>$values</span>[0] % 32 ) * 64 ) + ( <span>$values</span>[1] % 64<span> );
                    </span><span>$number</span> = <span>dechex</span>(<span>$number</span><span>);
                    </span><span>$unicode</span>[] = (<span>strlen</span>(<span>$number</span>)==3)?"\u0".<span>$number</span>:"\u".<span>$number</span><span>;
                    </span><span>$values</span> = <span>array</span><span>();
                    </span><span>$lookingFor</span> = 1<span>;
                } </span><span>//</span><span> if</span>
            } <span>//</span><span> if</span>
<span>        }
    } </span><span>//</span><span> for</span>
    <span>return</span> <span>implode</span>("",<span>$unicode</span><span>);
}</span>
Copy after login

参考文章:http://randomchaos.com/documents/?source=php_and_unicode

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/924849.htmlTechArticlephp中utf-8转unicode,phputf-8转unicode public function utf8_unicode( $str ) { $unicode = array (); $values = array (); $lookingFor = 1 ; for ( $i = 0; $i strlen ( $str ); $i ++...
Statement of this Website
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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to escape special characters using regular expressions in Go language How to escape special characters using regular expressions in Go language Jul 13, 2023 am 11:16 AM

How to escape special characters using regular expressions in Go Quote: Regular expressions are a powerful string matching tool that are very useful when processing text. However, in some cases, we may need to use some special characters in regular expressions, such as "+", "*", etc. These characters have special meanings in regular expressions. In order to use the literal meaning of these special characters, we need to escape them. This article will introduce how to use regular expressions to escape special characters in Go language, and provide code examples to illustrate.

What is the method to escape characters using less than or equal to in MyBatis? What is the method to escape characters using less than or equal to in MyBatis? Feb 24, 2024 am 11:12 AM

Using less than or equal to escape characters is a common requirement in MyBatis, and such situations are often encountered in the actual development process. Below we will introduce in detail how to use the less than or equal to escape character in MyBatis and provide specific code examples. First, we need to clarify how the less than or equal to escape characters are represented in SQL statements. In SQL statements, the less than or equal operator usually starts with "

How to escape common special characters in Golang How to escape common special characters in Golang Mar 22, 2023 pm 02:22 PM

In the Golang language, strings are an important data type because they are widely used for data storage, transmission, and processing. However, when processing strings, we often encounter situations where special characters need to be escaped. This article will introduce how to escape common special characters in Golang.

Escape techniques using the less than or equal operator in MyBatis Escape techniques using the less than or equal operator in MyBatis Feb 25, 2024 pm 09:03 PM

What are escape characters in MyBatis and how to use them? In MyBatis, sometimes we need to use comparison operators such as less than or equal to in SQL statements, but these operators have specific meanings in XML files and will be parsed as XML tags, causing errors. To solve this problem, we can escape using escape characters. This article will introduce the application skills of using the less than or equal operator in MyBatis and provide specific code examples. Escape characters In XML documents, some characters

What is the escape character for php newline? What is the escape character for php newline? Jul 10, 2023 pm 05:32 PM

The escape character for php newline is "\n". Steps to use: 1. Determine where you want to insert the newline character; 2. Use the escape character "\n" where you want to insert the newline character; 3. Make sure When working with strings, you use appropriate quotes at the beginning and end, use single quotes to quote the string, and make sure to use double quotes around "\n".

Java Program Example: Demonstrates Escape Characters in Regular Expressions Java Program Example: Demonstrates Escape Characters in Regular Expressions Sep 19, 2023 am 09:01 AM

Here, we will demonstrate the escape characters in Regex through a Java program. Before we dive into this topic, let's familiarize ourselves with the terms "escape characters" and "regular expressions." Regular Expression It is an abbreviation for regular expression. It is an API that allows users to define string patterns for finding, modifying and editing strings. Regular expressions are often used to define restricted string fields, such as email authentication and passwords. The java.util.regex package contains regular expressions. Escape Characters When a character is preceded by a backslash (\), it includes numbers, letters, and punctuation marks. The compiler treats these characters differently, and such characters are called escape characters. Some examples include:\n-in

What are JavaScript escape characters? What are JavaScript escape characters? Sep 04, 2023 am 11:03 AM

Escape characters in JavaScript are backslashes and quotes, which can represent special characters in a string or change the meaning of characters. Detailed introduction: 1. Backslash is an escape character in JavaScript. It can be used in combination with other characters to represent special characters. Use two backslashes to represent the backslash itself. Use backslashes to escape some special characters. defined as their ASCII code representation. Use backslashes to escape some non-printing characters to their Unicode representation; 2. Quotation marks, etc.

A brief analysis of escaping newline characters in PHP A brief analysis of escaping newline characters in PHP Mar 23, 2023 pm 05:20 PM

PHP is a very powerful programming language that can easily complete various tasks, including string processing. When processing strings, we can use escape characters in PHP to process special characters, such as single quotes, double quotes, and newline characters. This article will focus on escaping newlines in PHP.

See all articles