The original intention of the design is: the article list page. if you delete all styles with strip_tags, the articles on the homepage will look messy and have no styles. If you simply use strip_tags to retain p or br, p or br may be truncated when you intercept the string. The design concept is: retain p and br, then replace p with br, and then use br as the separator to separate the entire article. The code is as follows: you can directly use **... the original intention of the design is: the article list page. if you delete all styles with strip_tags, the articles on the homepage will look messy and have no styles. If you simply use strip_tags to retain p or br, p or br may be truncated when you intercept the string.
The design concept is: retain p and br, then replace p with br, and then use br as the separator to separate the entire article.
The code is as follows:
/*** Long article segmentation * @ param string $ article content * @ param number $ return_number article byte limit * @ return array */private function ContentAddpage ($ content, $ return_number = 800) {$ return_content = ""; // The Returned string $ current_num = 0; // The length of the current string $ return_content_num = 0; // The length after the last string truncation; it is used to process cases with long words in the last array. $ page_num_word = array (); // use preg_split as the separator to separate the array generated by the string; $ content = strip_tags ($ content ,',
'); $ Content = preg_replace ("/
/M ","
", $ Content); $ content = str_replace ("
"," ", $ Content); $ content = preg_replace ("/
/M ","
", $ Content); $ content_info = preg_split ("/\
/", $ Content); // Determine the paragraph according to 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]; // Obtain 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 )."
"; $ Response = $ current_num;} else {$ tmp_num = $ return_number-$ return_content_num; $ return_content. = mb_substr ($ content_info [$ I], 0, $ tmp_num )."
"; Break ;}} return $ return_content ;}