PHP long article pagination code sharing

WBOY
Release: 2016-07-25 08:53:26
Original
976 people have browsed it
  1. /**
  2. * Long article segmentation
  3. * @param string $article article content
  4. * @param number $return_number article byte limit
  5. * @return array
  6. */
  7. private function ContentAddpage($content,$return_number=800){
  8. $return_content = ""; //Returned string
  9. $current_num = 0 ; //Current string length
  10. $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.
  11. $page_num_word = array(); //separated by br The array generated by using preg_split to separate strings;
  12. $content = strip_tags($content,'

    ,
    ');

  13. $content = preg_replace("/", $content);
  14. $content = str_replace("

    ","", $content);
  15. $content = preg_replace("//m", "
    ", $content);
  16. $content_info = preg_split("/
    /",$content);//Determine the paragraph based on the string
  17. $art_num = count($content_info);//Determine the number of paragraphs
  18. for($i=0;$i <= $art_num-1;$i++){
  19. $page_num_word[$i] = strlen($content_info[$i] );
  20. $current_num += $page_num_word[$i];//Get the number of words
  21. if ($current_num <= $return_number){
  22. $tmp_num = $return_number-$current_num;
  23. $return_content .= mb_substr($content_info[ $i],0,$tmp_num)."
    ";
  24. $return_content_num = $current_num;
  25. }else{
  26. $tmp_num = $return_number-$return_content_num;
  27. $return_content .= mb_substr($content_info[$i ],0,$tmp_num)."
    ";
  28. break;
  29. }
  30. }
  31. return $return_content;
  32. }
Copy code

Articles you may be interested in:



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template