PHP long article page code sharing

Source: Internet
Author: User
  1. /**
  2. * Long article segment
  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 = ""; The returned string
  9. $current _num = 0; Current string length
  10. $return _content_num = 0; The length of the last string truncated, and the case in which the number of words in the last array is too long to handle.
  11. $page _num_word = Array ();//The array generated using the Preg_split delimited string with the BR delimiter;
  12. $content = Strip_tags ($content, '

    ,
    ');

  13. $content = Preg_replace ("// M", "
    ", $content);
  14. $content = Str_replace ("

    "," ", $content);

  15. $content = Preg_replace ("// M", "
    ", $content);
  16. $content _info = Preg_split ("/\ /", $content);//Determine paragraph by string
  17. $art _num = count ($content _info);//determine 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 word count
  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:

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.