-
- /**
- * 长文章分段
- * @param string $article 文章内容
- * @param number $return_number 文章字节限制
- * @return array
- */
- private function ContentAddpage($content,$return_number=800){
- $return_content = ""; //返回的字符串
- $current_num = 0; //当前字符串长度
- $return_content_num = 0; //上次字符串截取后的长度;用来处理最后数组中字数过长的case.
- $page_num_word = array();//以br为分隔符使用preg_split分隔字符串生成的数组;
-
- $content = strip_tags($content,'
, ');
- $content = preg_replace("/
/m", " ", $content);
- $content = str_replace("","", $content);
- $content = preg_replace("/
/m", " ", $content);
- $content_info = preg_split("/
/",$content);//根据字符串确定段落
- $art_num = count($content_info);//确定段落数
-
- for($i=0;$i <= $art_num-1;$i ){
- $page_num_word[$i] = strlen($content_info[$i]);
- $current_num = $page_num_word[$i];//得到字数
- if ($current_num <= $return_number){
- $tmp_num = $return_number-$current_num;
- $return_content .= mb_substr($content_info[$i],0,$tmp_num)."
";
- $return_content_num = $current_num;
- }else{
- $tmp_num = $return_number-$return_content_num;
- $return_content .= mb_substr($content_info[$i],0,$tmp_num)."
";
- break;
- }
- }
- return $return_content;
- }
复制代码
您可能感兴趣的文章:
|
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31