<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ls /proc &#187; 汉字</title>
	<atom:link href="http://www.lsproc.com/blog/tag/%e6%b1%89%e5%ad%97/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lsproc.com/blog</link>
	<description>lsproc.com</description>
	<lastBuildDate>Fri, 18 Nov 2011 09:22:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>生成随机汉字字符串 (UTF8)</title>
		<link>http://www.lsproc.com/blog/get_randnum_chinese_string/</link>
		<comments>http://www.lsproc.com/blog/get_randnum_chinese_string/#comments</comments>
		<pubDate>Wed, 07 Nov 2007 17:26:43 +0000</pubDate>
		<dc:creator>lostsnow</dc:creator>
				<category><![CDATA[Program&Database]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[字符串]]></category>
		<category><![CDATA[汉字]]></category>

		<guid isPermaLink="false">http://localhost/lost/blog/webdesign/get_randnum_chinese_string/</guid>
		<description><![CDATA[转载时请标明文章原始出处和作者信息, 作者: lostsnow.http://www.lsproc.com/blog/get_randnum_chinese_string/ &#60;?php $outputstr = getRandNumChineseString(); echo $outputstr; function getChineseCharacter() { $unidec = rand(19968, 40869); $unichr = &#039;&#38;#&#039; . $unidec . &#039;;&#039;; $zhcnchr = mb_convert_encoding($unichr, &#34;UTF-8&#34;, &#34;HTML-ENTITIES&#34;); return $zhcnchr; } function getRandNumChineseString() { $num = rand(1,16); $str = null; &#8230; <a href="http://www.lsproc.com/blog/get_randnum_chinese_string/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>转载时请标明文章原始出处和作者信息, 作者: <a href="http://www.lsproc.com/blog/">lostsnow</a>.<br /><a href="http://www.lsproc.com/blog/get_randnum_chinese_string/">http://www.lsproc.com/blog/get_randnum_chinese_string/</a></p>
<pre class="brush: php">&lt;?php
$outputstr = getRandNumChineseString();
echo $outputstr;
function getChineseCharacter()
{
$unidec = rand(19968, 40869);
$unichr = &#039;&amp;#&#039; . $unidec . &#039;;&#039;;
$zhcnchr = mb_convert_encoding($unichr, &quot;UTF-8&quot;, &quot;HTML-ENTITIES&quot;);
return $zhcnchr;
}

function getRandNumChineseString()
{
$num = rand(1,16);
$str = null;
for($i=0;$i&lt;$num;$i++)
{
$str = $str . getChineseCharacter();
}
return $str;
}
?&gt;</pre>
<p>PHP 需要开启 mbstring 支持<br />
附: <a href="http://www.chi2ko.com/tool/CJK.htm">汉字Unicode编码表</a>
<p>-- EOF --</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li>2006-03-01 -- <a href="http://www.lsproc.com/blog/intercept-chinese-char/" title="汉字截取的方法">汉字截取的方法</a> (2)</li><li>2010-05-21 -- <a href="http://www.lsproc.com/blog/nginx_php_pathinfo_securit/" title="Nginx/PHP 文件类型错误解析漏洞：fix_pathinfo">Nginx/PHP 文件类型错误解析漏洞：fix_pathinfo</a> (2)</li><li>2010-04-12 -- <a href="http://www.lsproc.com/blog/nginx_userid_decode/" title="nginx userid 模块客户端 cookie 解码">nginx userid 模块客户端 cookie 解码</a> (0)</li><li>2010-03-08 -- <a href="http://www.lsproc.com/blog/use_ob_flush_on_nginx_fastcgi/" title="nginx+factcgi 下使用 ob_flush">nginx+factcgi 下使用 ob_flush</a> (0)</li><li>2008-06-15 -- <a href="http://www.lsproc.com/blog/lighttpd_phpfastcgi_config/" title="lighttpd + PHP(fastcgi) 配置">lighttpd + PHP(fastcgi) 配置</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.lsproc.com/blog/get_randnum_chinese_string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>汉字截取的方法</title>
		<link>http://www.lsproc.com/blog/intercept-chinese-char/</link>
		<comments>http://www.lsproc.com/blog/intercept-chinese-char/#comments</comments>
		<pubDate>Wed, 01 Mar 2006 09:55:25 +0000</pubDate>
		<dc:creator>lostsnow</dc:creator>
				<category><![CDATA[WebDesign]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[汉字]]></category>

		<guid isPermaLink="false">http://lost.yi.org/blog/?p=12</guid>
		<description><![CDATA[转载时请标明文章原始出处和作者信息, 作者: lostsnow.http://www.lsproc.com/blog/intercept-chinese-char/ 原来有人提出了一个方法： $len = 19; $text = &#34;here is the text!&#34;; echo strlen($text)&#60; =$len ? $text : (substr($text,0,$len).chr(0).&#34;....&#34;); 在 SaBlog 的程序里发现了另一种方法： function csubstr ($text, $limit) { $s = &#039;; for($i=0;$i&#60; $limit-3;$i++) { $s .= ord($text[$i])&#62;127 ? $text[$i].$text[++$i] : &#8230; <a href="http://www.lsproc.com/blog/intercept-chinese-char/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>转载时请标明文章原始出处和作者信息, 作者: <a href="http://www.lsproc.com/blog/">lostsnow</a>.<br /><a href="http://www.lsproc.com/blog/intercept-chinese-char/">http://www.lsproc.com/blog/intercept-chinese-char/</a></p>
<p>原来有人提出了一个方法：</p>
<pre class="brush: php">
$len = 19;
$text = &quot;here is the text!&quot;;
echo strlen($text)&lt; =$len ? $text : (substr($text,0,$len).chr(0).&quot;....&quot;);
</pre>
<p>在 SaBlog 的程序里发现了另一种方法：</p>
<pre class="brush: php">
function csubstr ($text, $limit) {
    $s = &#039;;
    for($i=0;$i&lt; $limit-3;$i++) {
        $s .= ord($text[$i])&gt;127 ? $text[$i].$text[++$i] : $text[$i];
    }
    return $s;
}
</pre>
<p>以上仅适用于 gb2312 编码，如果是UTF-8 的话需要把第4行改为</p>
<pre class="brush: php">
$s .= ord($text[$i])&gt;127 ? $text[$i].$text[++$i].$text[++$i] : $text[$i];
</pre>
<p>UTF-8 中的汉字是 3 个字节。
<p>-- EOF --</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li>2007-11-08 -- <a href="http://www.lsproc.com/blog/get_randnum_chinese_string/" title="生成随机汉字字符串 (UTF8)">生成随机汉字字符串 (UTF8)</a> (0)</li><li>2010-05-21 -- <a href="http://www.lsproc.com/blog/nginx_php_pathinfo_securit/" title="Nginx/PHP 文件类型错误解析漏洞：fix_pathinfo">Nginx/PHP 文件类型错误解析漏洞：fix_pathinfo</a> (2)</li><li>2010-04-12 -- <a href="http://www.lsproc.com/blog/nginx_userid_decode/" title="nginx userid 模块客户端 cookie 解码">nginx userid 模块客户端 cookie 解码</a> (0)</li><li>2010-03-08 -- <a href="http://www.lsproc.com/blog/use_ob_flush_on_nginx_fastcgi/" title="nginx+factcgi 下使用 ob_flush">nginx+factcgi 下使用 ob_flush</a> (0)</li><li>2008-06-15 -- <a href="http://www.lsproc.com/blog/lighttpd_phpfastcgi_config/" title="lighttpd + PHP(fastcgi) 配置">lighttpd + PHP(fastcgi) 配置</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.lsproc.com/blog/intercept-chinese-char/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

