-
- /**
- * Long article segmentation
- * @param string $article article content
- * @param number $return_number article byte limit
- * @return array
- */
- private function ContentAddpage($content,$return_number=800){
- $return_content = ""; //Returned string
- $current_num = 0 ; //Current string length
- $return_content_num = 0; //The length after the last string interception; used to handle cases where the number of words in the final array is too long.
- $page_num_word = array(); //separated by br The array generated by using preg_split to separate strings;
-
- $content = strip_tags($content,'
, ');
- $content = preg_replace("/
", $content);
- $content = str_replace("","", $content);
- $content = preg_replace("/
/m", " ", $content);
- $content_info = preg_split("/
/",$content);//Determine the paragraph based on the string
- $art_num = count($content_info);//Determine the number of paragraphs
-
- for($i=0;$i <= $art_num-1;$i++){
- $page_num_word[$i] = strlen($content_info[$i] );
- $current_num += $page_num_word[$i];//Get the number of words
- 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;
- }
Copy code
Articles you may be interested in:
|