[分享][讨论][求助]请教:如何用PHP或JS控制:标题限制为4-20个汉字,内容10-3000个
<P>如何用PHP或JS控制:标题限制为4-20个汉字,内容10-3000个汉字呢?此文本大致如下:谢谢!</P><P><html><BR><head><BR></head><BR><body></P>
<P> <form method='POST' action='fbjypx_yjzlb.php?action=login'><BR> <table border="0" align="center" width="750" cellspacing="0" cellpadding="0"><BR> <tr><BR> <td width="100%" class="f2">密&nbsp;&nbsp;码:<input type="text" name="mm" size="20" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''"><BR> </td> <BR> </tr><BR> <tr><BR> <td width="100%" class="f2">标&nbsp;&nbsp;题:<input type="text" name="bt" size="40" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''"><BR> <font class="f1">(23个汉字以内)</font></td> <BR> </tr><BR> <br><BR> <tr><BR> <td width="100%" class="f2">内&nbsp;&nbsp;容:<font class="f1">(3000个汉字以内)</font></td><BR> </tr><BR> <tr><BR> <td width="100%" ><BR> <textarea rows="20" name="nr" cols="105" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''"></textarea></td><BR> </tr><BR> <tr><BR> <td width="100%" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR> <input type="submit" value="提&nbsp;交">&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="重&nbsp;来"></td><BR> </tr><BR> </table><BR> </form><BR></body><BR></html><BR></P> strlen 获取字符串长度<BR>substr 截取字符串 <P>PHP原有函数对中英混合的支持不大好<BR><BR>如果有mb_扩展直接用就可以了<BR><BR>没有的话用这个函数<BR><BR>function strSplit($s, $len) {<BR> $end = '…';<BR> $result = '';<BR> $strLen = strlen($s);<BR> if ($strLen <= $len) {<BR> return $s;<BR> }<BR> $len -= 2;<BR> for ($i=0; $i<$len && $i<$strLen; $i++) {<BR> $c = $s[$i];<BR> if (ord($c) < 0x80) {<BR> $result .= $c;<BR> } elseif ($i+1<$len) {<BR> $result .= $s[$i++] . $s[$i];<BR> }<BR> }<BR> return ($i < $strLen) ? ($result . $end) : $result;<BR>}</P>
<P>echo strSplit('1234567', 10), '<br />';<BR>echo strSplit('1234567890', 10), '<br />';<BR>echo strSplit('1234中文567890abcdefghijkl', 10), '<br />';<BR>echo strSplit('全部都是中文', 10), '<br />';<BR>echo strSplit('全a部b都c是d中e文', 10), '<br />'; <BR></P>
页:
[1]
