Can't Chinese characters be placed in the php array?

青灯夜游
Release: 2023-03-16 18:28:01
Original
1811 people have browsed it

Chinese characters can be placed in the php array. Because PHP is a programming language with weak data types, arrays in PHP can store any number of data of any type, that is, there is no limit on the type of array elements, which can be numbers, Boolean values, arrays, strings, etc.; while strings It can be divided into pure English strings, pure Chinese strings and mixed Chinese and English strings.

Can't Chinese characters be placed in the php array?

The operating environment of this tutorial: windows7 system, PHP version 8.1, DELL G3 computer

Array is one of the most important data types in PHP First, it is widely used in PHP. Because PHP is a programming language with weak data types, array variables in PHP can store any number of data of any type, and can implement the functions of data structures such as heaps, stacks, and queues in other strong data types.

Simply put,There is no restriction on the type of PHP array elements, which can be numbers, strings, Boolean values, arrays, Object objects, etc.

A string is a continuous sequence of characters, consisting of a series of characters, where each character is equivalent to one byte.

Strings can be divided into pure English strings, pure Chinese strings and mixed Chinese and English strings. Therefore, Chinese characters can be placed in the php array.

Example 1: Put pure English strings in php array

Copy after login

Cant Chinese characters be placed in the php array?

Example 2: php array Put the pure Chinese string

Copy after login

Cant Chinese characters be placed in the php array?

. It should be noted that in PHP, one Chinese character occupies three characters, so the length of the two Chinese strings in the above example For 6.

Example 3: Put Chinese and English mixed strings in the php array

Copy after login

Cant Chinese characters be placed in the php array?

Extended knowledge: Chinese Two processing functions for strings

1. Chinese interception: mb_substr()

mb_substr( $str, $start, $length, $encoding )
Copy after login
  • $str, the string that needs to be truncated

  • $start, the starting point of truncation, the starting point is 0

  • ##$length, the number of words to be intercepted

  • $encoding, web page encoding, such as utf-8, GB2312, GBK

  • Copy after login

Cant Chinese characters be placed in the php array?

2. Get the Chinese length: mb_strlen()

mb_strlen( $str, $encoding )
Copy after login

  • $str, the string whose length needs to be calculated

  • $encoding, web page encoding, such as utf-8, GB2312, GBK

  • Copy after login

    Cant Chinese characters be placed in the php array?

    Recommended learning: "

    PHP Video Tutorial"

    The above is the detailed content of Can't Chinese characters be placed in the php array?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!