Home > Backend Development > PHP Tutorial > 如何生成指定长度的中文字符串

如何生成指定长度的中文字符串

WBOY
Release: 2016-06-23 13:49:22
Original
981 people have browsed it

如何用 “思雅美诗若淑梓清丹佩紫秋瑞颖爱曼林?璐春博云” 这些汉字,循环生成多个由2个汉字的组成的字符串?


回复讨论(解决方案)

最笨的方法,循环判断取模

采用随机数来获取2个字然后塞进数组里面打印出来就可以了。

谁能提供代码,我产生的都是乱码。不知道什么原因。

$s = '思雅美诗若淑梓清丹佩紫秋瑞颖爱曼林?璐春博云';$chunk = mb_check_encoding($s, 'utf-8') ? 3 : 2;$a = str_split($s, $chunk);shuffle($a);print_r(array_map('join', array_chunk($a, 2)));
Copy after login

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template