- <?php
- function englishSubstr($str,$start,$end)
- {
- if($start!=0)
- {
- if(substr($str,$start-1,1)!=" ")//如果被截的字母前面一个不是空格,表格这个字母并不是一个单词的开始
- {
- //那么我们就去除第一个不完整单词
- $i;
- for($i=1;$i<20;$i++)
- {
- if(substr($str,$start+$i,1)==" ") //向下循环,直到空格为止,然后高空格后的第一个字母为分页的第一个单词的开始
- {
- break;
- }
- }
- $start+=$i;
- }
- }
- if(substr($str,$end,1)!="")//如果结束处不是空格,表示一个单词还没有完
- {
- $i;
- for($i=1;$i<20;$i++)//往下循环,直到找到空格后退出,
- {
- if(substr($str,$start+$end+$i,1)==" ")
- {
- break;
- }
- }
- $end+=$i;
- }
- //获取分断单词
- return substr($str,$start,$end);
- }
- //该片段来自于http://www.codesnippet.cn/detail/121020136364.html
来源: http://www.codesnippet.cn/detail/121020136364.html