Home > Backend Development > PHP Tutorial > 各位大神,字串中随机插入汉字

各位大神,字串中随机插入汉字

WBOY
Release: 2016-06-23 13:33:59
Original
1051 people have browsed it

各位大神,请教个字串中随机插入汉字的问题
比如:
$a="你我他它她";
$b="ilove上海每一天";

从$a中随机取一个汉字插入到$b中,结果如下:
ilo 他ve上海每一天

ilove上 我海每一天

注意:$b中可能有字母、数字、汉字


回复讨论(解决方案)

iconv_set_encoding("internal_encoding", "GBK"); //根据你的字符修改$a = "你我他它她";$b = "ilove上海每一天";$c = iconv_substr($a, rand(0, iconv_strlen($a)-1), 1);$n = rand(0, iconv_strlen($b)-1);echo iconv_substr($b, 0, $n) . $c . iconv_substr($b, $n);
Copy after login
Copy after login

iconv_set_encoding("internal_encoding", "GBK"); //根据你的字符修改$a = "你我他它她";$b = "ilove上海每一天";$c = iconv_substr($a, rand(0, iconv_strlen($a)-1), 1);$n = rand(0, iconv_strlen($b)-1);echo iconv_substr($b, 0, $n) . $c . iconv_substr($b, $n);
Copy after login
Copy after login



perfect!tks!
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