I have a story with a little over 500 words in it. Is there anyway I can insert an image every 100 words?
I've been playing with explode() ing the story at every space, array_slice() ing / implode() ing the story back together without much luck. It kind of works but the middle portions of the story repeat in the wrong order, it's strange. Is there an easier way to do this?
Here is and example of what I've been messing with if someone wants to play with it... What I'm looking for is this script to just count to 24 inserting an image every 8 numbers (this is just a test script, trying to debug)...
<?
$body = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24";
$num_pics = 3;
moreThanOne($body,$num_pics);
function moreThanOne($body,$num_pics) {
// create array from story split at spaces //
$newsbody = explode(" ", $body);
// count words in story //
$newsbody_count = count($newsbody);
// where to split story so images show evenly //
$newsbody_split_count = round($newsbody_count / $num_pics);
$countmeup = 0;
for($ix=0; $ix < $num_pics; $ix++) {
$countmestart = $countmeup;
$countmeup = ($countmeup + $newsbody_split_count);
// start putting story back together at //
// starting point of $countmestart //
// and ending point of $countmeup //
$newsbody_paste = array_slice($newsbody,$countmestart,$countmeup);
echo "<br><b>From $countmestart to $countmeup >> </b>";
if ($ix < ($num_pics - 1)) {
echo "<b>insert photo</b><br>";
echo implode(" ", $newsbody_paste);
}else{
echo "<b>finish story</b><br>";
echo implode(" ", $newsbody_paste);
}
}
}
?>
Thanks everyone.