<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[BIWEB开源PHP WMS系统创始人ArthurXF肖飞的blog]]></title> 
<link>http://www.bizeway.net/index.php</link> 
<description><![CDATA[网务通 - 网务公司发展之路]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[BIWEB开源PHP WMS系统创始人ArthurXF肖飞的blog]]></copyright>
<item>
<link>http://www.bizeway.net/read.php?</link>
<title><![CDATA[Wap用utf8中文字符截取和utf8按照字数分页函数]]></title> 
<author>ArthurXF &lt;arthurxf@gmail.com&gt;</author>
<category><![CDATA[PHP]]></category>
<pubDate>Tue, 06 Feb 2007 10:22:54 +0000</pubDate> 
<guid>http://www.bizeway.net/read.php?</guid> 
<description>
<![CDATA[ 
	　　当一篇文章太长时，比如大于1000字，在手机中需要分页，这个时候分页是按字数多少来进行分页的，虽然手机可以显示超过200个汉字，但是实际情况中，根据手机屏幕的大小，我们一般采取每页200个汉字，即：400个字符。 <br/><br/><br/>通用按字数分页方法，适合中英文混排。 <br/>使用WordPage($str,200);调用就可以了。 <br/><br/><br/><div class="code">&lt;?php <br/>//此文件UTF-8格式 <br/>/**<br/>* 支持utf8中文字符截取<br/>* @author &nbsp;肖飞(arthurxf@gmail.com) <br/>* @param &nbsp;string $text &nbsp; &nbsp;待处理字符串<br/>* @param &nbsp;int $start &nbsp; &nbsp; &nbsp;从第几位截断<br/>* @param &nbsp;int $sublen &nbsp; &nbsp;截断几个字符<br/>* @param &nbsp;string $code &nbsp; &nbsp;字符串编码<br/>* @param &nbsp;string $ellipsis &nbsp; &nbsp;附加省略字符<br/>* @return &nbsp;string<br/>*/<br/>function csubstr($string, $start = 0,$sublen=12, $code = &#039;UTF-8&#039;,$ellipsis=&#039;...&#039;){<br/> &nbsp;if($code == &#039;UTF-8&#039;){<br/> &nbsp; &nbsp;$pa = &quot;/&#91;&#92;x01-&#92;x7f&#93;&amp;#124;&#91;&#92;xc2-&#92;xdf&#93;&#91;&#92;x80-&#92;xbf&#93;&amp;#124;&#92;xe0&#91;&#92;xa0-&#92;xbf&#93;&#91;&#92;x80-&#92;xbf&#93;&amp;#124;&#91;&#92;xe1-&#92;xef&#93;&#91;&#92;x80-&#92;xbf&#93;&#91;&#92;x80-&#92;xbf&#93;&amp;#124;&#92;xf0&#91;&#92;x90-&#92;xbf&#93;&#91;&#92;x80-&#92;xbf&#93;&#91;&#92;x80-&#92;xbf&#93;&amp;#124;&#91;&#92;xf1-&#92;xf7&#93;&#91;&#92;x80-&#92;xbf&#93;&#91;&#92;x80-&#92;xbf&#93;&#91;&#92;x80-&#92;xbf&#93;/&quot;;<br/> &nbsp; &nbsp;preg_match_all($pa, $string, $t_string);<br/><br/> &nbsp; &nbsp;if(count($t_string&#91;0&#93;) - $start &gt; $sublen) return join(&#039;&#039;, array_slice($t_string&#91;0&#93;, $start, $sublen)).$ellipsis;<br/> &nbsp; &nbsp;return join(&#039;&#039;, array_slice($t_string&#91;0&#93;, $start, $sublen));<br/> &nbsp;}else{<br/> &nbsp; &nbsp;$start = $start*2;<br/> &nbsp; &nbsp;$sublen = $sublen*2;<br/> &nbsp; &nbsp;$strlen = strlen($string);<br/> &nbsp; &nbsp;$tmpstr = &#039;&#039;;<br/> &nbsp; &nbsp;for($i=0; $i&lt;$strlen; $i++){<br/> &nbsp; &nbsp; &nbsp;if($i&gt;=$start &amp;&amp; $i&lt;($start+$sublen)){<br/> &nbsp; &nbsp; &nbsp; &nbsp;if(ord(substr($string, $i, 1))&gt;129) $tmpstr.= substr($string, $i, 2);<br/> &nbsp; &nbsp; &nbsp; &nbsp;else $tmpstr.= substr($string, $i, 1);<br/> &nbsp; &nbsp; &nbsp;} <br/> &nbsp; &nbsp; &nbsp;if(ord(substr($string, $i, 1))&gt;129) $i++;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;if(strlen($tmpstr)&lt;$strlen ) $tmpstr.= $ellipsis;<br/> &nbsp; &nbsp;return $tmpstr;<br/> &nbsp;}<br/>}<br/><br/>/**<br/> * 支持utf8按照字数分页<br/> * @author &nbsp;肖飞 <br/> * @param &nbsp;string $str &nbsp;待处理字符串<br/> * @param &nbsp;int $page &nbsp; &nbsp;当前页面<br/> * @param &nbsp;int $num &nbsp; &nbsp;从第几页截断<br/> * @param &nbsp;string $code &nbsp;字符串编码<br/> * @return &nbsp;string<br/> */<br/>function WordPage($str,$num=200,$page,$code = &#039;UTF-8&#039;){<br/> &nbsp;/*下面这段对多字节字符计算不准，主要是strlen产生的误差，所以建议使用下面的程序<br/> &nbsp;if($code == &#039;UTF-8&#039;) $PageAll = strlen($str)/($num*3);<br/> &nbsp;else $PageAll = strlen($str)/($num*2);<br/> &nbsp;*/ &nbsp;<br/> &nbsp;$PageAll = mb_strlen($str,$code)/$num;<br/> &nbsp;$PageAll = ceil($PageAll); <br/> &nbsp;if ($page==&quot;&quot;){<br/> &nbsp; &nbsp;$page = 1; <br/> &nbsp;}<br/> &nbsp;$start = ($page-1)*$num; <br/> &nbsp;<br/> &nbsp;$str = csubstr($str, $start, $num,$code,&#039;&#039;);<br/> &nbsp;$arrData = array();<br/> &nbsp;$arrData&#91;&#039;centent&#039;&#93; = $str;<br/> &nbsp;//echo $str.&#039;&lt;br /&gt;&#039;;<br/> &nbsp;<br/> &nbsp;if( (1&lt;=$page) &amp;&amp; ($page&lt;=$PageAll)){<br/> &nbsp; &nbsp;if($page &lt; $PageAll){<br/> &nbsp; &nbsp; &nbsp;$arrData&#91;&#039;pagedown&#039;&#93; = $page+1;<br/> &nbsp; &nbsp; &nbsp;//echo &#039;&lt;a href=&quot;&#039;.$_SERVER&#91;&quot;PHP_SELF&quot;&#93;.&#039;?page=&#039;.($page+1).&#039;&amp;id=&#039;.$_GET&#91;&#039;id&#039;&#93;.&#039;&quot;&gt;下一页&lt;/a&gt;&lt;br /&gt;&#039;; <br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;if( $page&gt;1 ){<br/> &nbsp; &nbsp; &nbsp;$arrData&#91;&#039;pageup&#039;&#93; = $page-1;<br/> &nbsp; &nbsp; &nbsp;//echo &#039;&lt;a href=&quot;&#039;.$_SERVER&#91;&quot;PHP_SELF&quot;&#93;.&#039;?page=&#039;.($page-1).&#039;&amp;id=&#039;.$_GET&#91;&#039;id&#039;&#93;.&#039;&quot;&gt;上一页&lt;/a&gt;&lt;br /&gt;&#039;; <br/> &nbsp; &nbsp;}<br/> &nbsp;}<br/> &nbsp;$arrData&#91;&#039;pagenav&#039;&#93; = &#039;第&#039;.$page.&#039;页/共&#039;.$PageAll.&#039;页&#039;; <br/> &nbsp;//echo &#039;第&#039;.$page.&#039;页/共&#039;.$PageAll.&#039;页&lt;br /&gt;&#039;;<br/> &nbsp;return $arrData;<br/>}<br/>?&gt;</div><br/>Tags - <a href="tag.php?tag=wap" rel="tag">wap</a> , <a href="tag.php?tag=%E5%88%86%E5%B1%8F" rel="tag">分屏</a> , <a href="tag.php?tag=%E5%88%86%E9%A1%B5" rel="tag">分页</a> , <a href="tag.php?tag=php" rel="tag">php</a>
]]>
</description>
</item><item>
<link>http://www.bizeway.net/read.php?&amp;guid=0#topreply</link>
<title><![CDATA[[评论] Wap用utf8中文字符截取和utf8按照字数分页函数]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.bizeway.net/read.php?&amp;guid=0#topreply</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>