swamp Posted August 14, 2008 Share Posted August 14, 2008 Hey, My script at the moment is this: <?php $str = $post; echo nl2br(chunk_split($str,900," </div><div id='content_2'><p>")); ?> Which splits the $post into chunks of 900 characters, after 900 characters it puts it in div 'content_2" - this is good if my $post is under 1800 characters, but not so good if it is more than this. How would I go about putting the next 900 characters in content_3, the 900 after that in content_4 etc etc... Any help much appreciated! Quote Link to comment Share on other sites More sharing options...
taith Posted August 14, 2008 Share Posted August 14, 2008 maybe not the fastest way of doing this... but... <? $i=1; for($t=0; $t<strlen($string);$t++){ if($t%900==0) $i++; $out[$i].=$string{$t}; } ?> which will break the string up into groups of 900 chars... then you simply foreach the $out to insert the div's :-) <? foreach($out as $k=>$v) $out[$k]='<div id="content_'.$k.'">'.$v.'</div>'; $out=implode('',$out); ?> and presto... $out now contains your text, in groups of 900 chars, seperated into <div>s that are sequentially numbered Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.