Ok, I'm trying a large experiment. This would consist of large posts (in the 500-800 words) and wanted to have the post split every 200 words or so, like a book.

I know I can do that by manually adding the 'nextpage' tag but then I'd manually have to count words and place the tag.I already have many articles in my db and adding the nextpage tag in each would mean suicide.Also I preffer the pages to have the same amount of words.

Does anyone know of a plugin that will split a post multiple times at a certain amount of word?

Ok, I'm trying a large experiment. This would consist of large posts (in the 500-800 words) and wanted to have the post split every 200 words or so, like a book.

I know I can do that by manually adding the 'nextpage' tag but then I'd manually have to count words and place the tag.I already have many articles in my db and adding the nextpage tag in each would mean suicide.Also I preffer the pages to have the same amount of words.

Does anyone know of a plugin that will split a post multiple times at a certain amount of word?

<?php
$strText = "all of my text, thousands of words to split into sets of 200";

$arrTextArray = array();
$intWordsPerPage = 200;
$intArrayCounter = 0;
$intLoopCounter = 0;
foreach(explode(" ", trim($strText)) as $value)
{
        $intLoopCounter++;
	if($intLoopCounter % $intWordsPerPage == 0) $intArrayCounter++;
	
	$arrTextArray[$intArrayCounter] .= (trim($arrTextArray[$intArrayCounter]) != ""?" ":"") . $value;
}
?>

This should give you an array, each cell containing 200 words, the last containing up to 200 words.

<?php
$strText = "all of my text, thousands of words to split into sets of 200";

$arrTextArray = array();
$intWordsPerPage = 200;
$intArrayCounter = 0;
$intLoopCounter = 0;
foreach(explode(" ", trim($strText)) as $value)
{
        $intLoopCounter++;
	if($intLoopCounter % $intWordsPerPage == 0) $intArrayCounter++;
	
	$arrTextArray[$intArrayCounter] .= (trim($arrTextArray[$intArrayCounter]) != ""?" ":"") . $value;
}
?>

This should give you an array, each cell containing 200 words, the last containing up to 200 words.

Hi,
Thanks for the reply.
This code splits any text into 200 words ,it's correct.
But wordpress uses <!- nextpage -> tag to generate multiple pages,so if I use your code on the output and I choose to get to page 2, I will get an 404 not found error.
I am looking for something that will edit each article that I add to the database and automatically add the <!-nextpage-> tag into that post , after 200 words.But 200 spaces don't mean 200 words always.
The HTML line break

<br />

code also contains a space so this becomes a little tricky complicated ,because of this exception.

A suggestion would be to use PHP htmlentities function to eliminate all the HTML code , then split the words by spaces, and find the 200th word.
Then go to the original code,and replace the 200th word with that word followed by the nextpage tag.
I am waiting for some suggestions before I will implement this.
This idea just came to me now.
I think it look good as a plugin with a SCAN button and a form to enter the number of words per page.
On each scan the nextpage tag would be removed and then it will be added after the right number of words.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.