New Features of PHP6: Unicode and TextIterator-PHP source code

Source: Internet
Author: User
Tags php unicode
Ec (2); I just installed PHP6DEV and decided to test the new feature of PHP6-PHP Unicode support. I am not planning to talk about the new features of PHP6 or Unicode. The following is just my Unicode test. First, let php6 support Unicode and modify it in the php. ini file .;;;;;;;;;;;;;;;;;;;;; Unicodesettings; script ec (2); script

I just installed PHP6 DEV and decided to test the new feature of PHP6-PHP Unicode support. I am not planning to talk about the new features of PHP6 or Unicode. The following is just my Unicode test.

The first thing to do is to make php6 support Unicode and modify it in the php. ini file.

;;;;;;;;;;;;;;;;;;;;
; Unicode settings;
; Unicode. semantics = on
Unicode. runtime_encoding = UTF-8
Unicode. script_encoding = UTF-8
Unicode. output_encoding = UTF-8
Unicode. from_error_mode = U_INVALID_SUBSTITUTE
Unicode. from_error_subst_char = 3f
Because I use different French and English, some characters need to be processed.
So, the purpose of my first test is to test the Unicode of strlen functions...

$ Word = "inclutre ";
Echo "Length:". strlen ($ word );

Result: Length: 4. The results are very correct... ... But it's just the beginning! :)

My second test object is the TextIterator in the new SPL of PHP6.
$ Word = "inclutre ";
Foreach (new TextIterator ($ word, TextIterator: CHARACTER) as $ character ){
? Var_inspect ($ character );
}

Output: unicode (1) "bytes" {00ea} unicode (1) "t" {0074} unicode (1) "r" {0072} unicode (1) "e" {0065}
Break down words and get a lot of letters and letters...

TextIterator: CHARACTER operations look very powerful, but TextIterator: WORD is more powerful.

$ Sentences = "Bonjour, nous sommes français! A ï e :)";
Foreach (new TextIterator ($ sentences, TextIterator: WORD) as $ word ){
Var_inspect ($ word );
}

Result: unicode (7) "Bonjour" {0042 006f 006e 006a 006f 0075 0072} unicode (1) "," {002c} unicode (1) "{0020} unicode (4)" nous "{006e 006f 0075 0073} unicode (1)" {0020} unicode (6) "sommes" {0073 006f 006d 006d 0065 0073} unicode (1) "{0020} unicode (8) "français" {0046 0072 0061 006e 00e7 0061 0069 0073} unicode (1) "{0020}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.