Home  >  Article  >  Backend Development  >  诸位大神,字串中随机插入汉字

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

WBOY
WBOYOriginal
2016-06-13 12:20:421082browse

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

本帖最后由 aitxtbbs 于 2015-05-26 19:41:34 编辑 各位大神,请教个字串中随机插入汉字的问题
比如:
$a="你我他它她";
$b="ilove上海每一天";

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

ilove上海每一天

注意:$b中可能有字母、数字、汉字
------解决思路----------------------
iconv_set_encoding("internal_encoding", "GBK"); //根据你的字符修改<br />$a = "你我他它她";<br />$b = "ilove上海每一天";<br /><br />$c = iconv_substr($a, rand(0, iconv_strlen($a)-1), 1);<br />$n = rand(0, iconv_strlen($b)-1);<br /><br />echo iconv_substr($b, 0, $n) . $c . iconv_substr($b, $n);
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