Heim  >  Artikel  >  Backend-Entwicklung  >  自动分页的不完整解决方案_PHP教程

自动分页的不完整解决方案_PHP教程

WBOY
WBOYOriginal
2016-07-21 15:58:21871Durchsuche

测试代码


  
  


$content=$_POST["content"];
//echo $content;
$ft=array("
","");
//echo count($ft);

$html = "abaaaaaaa
cssssssssssssssssssd
efdddddddddddddddddd";
preg_match_all ("|(
)|U",$html,$out, PREG_PATTERN_ORDER);
 while (list($key,$value) = each($out[1])) {

 }


$keywords = preg_split ("/(
)/", $html);
//echo $html;
$pagesize=10;
$size=0;
$h="";
for ($i=0; $i if($size $size+=strlen($keywords[$i]);
// echo "size=".$size;
 $h.=$keywords[$i];
 }
}

echo $h;
?>

思路是使用 
 将文章内容分解为多个块.形成数组
然后遍例,同时将文章内容块,一点点组合,直到它的长度大于 $pagesize

这是一个不错的方法,使用正则的 preg_split 进行文章内容的分割,是考虑到,以后不光使用
 同时使用   或者更多的分割符号

但问题是,同时使用多个分割符后, 无法判断某一段是根据哪个分割符进行分割的. 无法对文章内容完整还原

项目比较紧,而且添加文章的编辑器是fckeditor,每个文章都有n多的 br>.就暂时不考虑多个分割符了

 所以还不算是完整的解决方案. 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/317606.htmlTechArticle测试代码 formid="form1"name="form1"method="post"action="" textareaname="content"cols="60"rows="10"/textarea inputtype="submit"name="Submit"value="提交"/ /form ? $content=$_POS...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn