生成随机汉字字符串 (UTF8)

转载时请标明文章原始出处和作者信息, 作者: lostsnow.
http://www.lsproc.com/blog/get_randnum_chinese_string/

<?php
$outputstr = getRandNumChineseString();
echo $outputstr;
function getChineseCharacter()
{
$unidec = rand(19968, 40869);
$unichr = '&#' . $unidec . ';';
$zhcnchr = mb_convert_encoding($unichr, "UTF-8", "HTML-ENTITIES");
return $zhcnchr;
}

function getRandNumChineseString()
{
$num = rand(1,16);
$str = null;
for($i=0;$i<$num;$i++)
{
$str = $str . getChineseCharacter();
}
return $str;
}
?>

PHP 需要开启 mbstring 支持
附: 汉字Unicode编码表

-- EOF --

Related Posts

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>