A simple example of splitting a Chinese string into an array using php

Source: Internet
Author: User
A simple example of splitting a Chinese string into an array using php
This article introduces an example of using php to quickly split Chinese strings into arrays for your reference.

In php, it is very easy to split strings, mainly using the preg_match_all function. When processing a string containing Chinese characters, you can use the following method:

     

Output result: array ([0] => h [1] => I [2] => fishing [3] => fish [4] => Island [5] => Yes [6] => China [7] => country [8] =>)

Note: The pattern modifier u is fully supported in php5.

Example 2: use PHP to separate Chinese Strings

Split the string "love lotus" into "love", "Lotus", and "Say.

Use the php function preg_match_all. Example:

     

Output result: array 0 => array 0 => string 'ay' (length = 3) 1 => string 'loan' (length = 3) 2 => string ''(length = 3). you can obtain a specific word through an array.

For more information about how to use php to separate Chinese and English strings, see: php to separate Chinese and English strings.

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.