文章标签 ‘汉字’

转载时请标明文章原始出处和作者信息, 作者: 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 --

2007年11月8日01:26 | 没有评论
标签: , ,

转载时请标明文章原始出处和作者信息, 作者: lostsnow.http://www.lsproc.com/blog/intercept-chinese-char/
原来有人提出了一个方法:

$len = 19;
$text = "here is the text!";
echo strlen($text)< =$len ? $text : (substr($text,0,$len).chr(0)."....");

在 SaBlog 的程序里发现了另一种方法:

function csubstr ($text, $limit) {
$s = ';
for($i=0;$i< $limit-3;$i++) {
$s .= ord($text[$i])>127 ? $text[$i].$text[++$i] : $text[$i];
}
[...]

2006年3月1日17:55 | 2 条评论
分类: WebDesign
标签: ,