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

How to convert Chinese string to array in php

藏色散人
藏色散人Original
2020-08-24 09:51:263128browse

php Method to convert Chinese string to array: First create a PHP sample file; then define a Chinese string; then use functions such as "mb_substr" to convert the Chinese string into an array.

How to convert Chinese string to array in php

Recommended: "PHP Video Tutorial"

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 string to array in php

The above is the detailed content of How to convert Chinese 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