生成随机汉字字符串 (UTF8)
<?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;
}
?>
$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编码表
相关日志
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments
还没有评论。
发表评论