Home  >  Article  >  Backend Development  >  How to convert Chinese character string to array in php

How to convert Chinese character string to array in php

藏色散人
藏色散人Original
2021-07-16 10:54:152303browse

php method of converting Chinese character string to array: first create a PHP sample file; then define a Chinese character string; finally convert the Chinese character into an array through methods such as "mb_strlen($topictitle, 'utf-8');" Just convert the string into an array.

How to convert Chinese character string to array in php

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer

php How to convert a Chinese character string into an array?

php Convert Chinese character string to array[]

Code:

$topictitle="沙漠骆驼";
$length = mb_strlen($topictitle, 'utf-8');
$titlearray = [];
for ($i=0; $i<$length; $i++)  
{
$titlearray[] = mb_substr($topictitle, $i, 1, &#39;utf-8&#39;);    
}
 
return $titlearray;

Effect:

How to convert Chinese character string to array in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to convert Chinese character string to array in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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