Test code
<Form id = "form1" name = "form1" method = "post" action = "">
<Textarea name = "content" cols = "60" rows = "10"> </textarea>
<Input type = "submit" name = "Submit" value = "submit"/>
</Form>
<?
$ Content = $ _ POST ["content"];
// Echo $ content;
$ Ft = array ("<br/>", "</p> ");
// Echo count ($ ft );
$ Html = "abaaaaaaa <br/> cssssssssssssssssssd <br/> efdddddddddddddddddd ";
Preg_match_all ("| (<br \/>) | U", $ html, $ out, PREG_PATTERN_ORDER );
While (list ($ key, $ value) = each ($ out [1]) {
}
$ Keywords = preg_split ("/(<br \/>)/", $ html );
// Echo $ html;
$ Pagesize = 10;
$ Size = 0;
$ H = "";
For ($ I = 0; $ I <count ($ keywords); $ I ++ ){
If ($ size <$ pagesize ){
$ Size + = strlen ($ keywords [$ I]);
// Echo "size =". $ size;
$ H. = $ keywords [$ I];
}
}
Echo $ h;
?>
The idea is to use <br/> to separate the content of the article into multiple blocks to form an array.
Next, repeat the example and combine the content blocks until the length is greater than $ pagesize.
This is a good method. The regular preg_split is used to split the content of the article, considering that not only <br/> but also </p> or more separator will be used in the future.
However, the problem is that after multiple delimiters are used at the same time, you cannot determine which delimiter a segment is based on. You cannot completely restore the content of the article.
The project is tight, and the editor for adding an article is fckeditor. Each article has more than n </br>. multiple separators are not considered for the moment.
So it is not a complete solution.