Helping ordinary people create extraordinary websites!

How To Put Your Articles Into Separate Pages

By Ben Sinclair
2005-04-09

The Code
Now that your article has been "cut up", you'll need this code belwo the above code:



<?php
// Remove this code below if you don't
// what it to add breaks (<BR<) automatically.
$article = nl2br($article);

// Make sure there are no stuff ups.
if ($pages < 1) {
if (!$page || $page <= "0") {
$page = "1";
}
$article = "{ENDPAGE0} ".$article;
$pagea = $page - 1;
$pageb = $page + 1;

// Check that the page exists
$match_count = preg_match_all("/{ENDPAGE"."$pagea"."}(.*?){ENDPAGE"."$page"."}/is", $article, $matches);
if ($match_count == "" || $match_count == "0") {
$article = "This page does not exist!";
} else {
if( preg_match( "/{ENDPAGE"."$pagea"."}(.*?){ENDPAGE"."$page"."}/is", $article, $match ) )
$article = $match[1];
}

// Generate Page Numbers
if ($page < "1") {
$prev = "<a href=\"$PHP_SELF?page=$pagea\"<<< Prev</a< :";
} else {
$prev = "<< Prev :";
}
if ($page < "$pages") {
$next = ": <a href=\"$PHP_SELF?page=$pageb\"<Next <<</a<";
} else {
$next = ": Next <<";
}
for ($p=1 ;$p <=$pages  ; $p++ )
{
if ($page == $p) {
$direct_bar .= "<b<$p</b< ";
} else {
$direct_bar .= "<a href=\"$PHP_SELF?page=$p\"<$p</a< ";
}
}
}

// Finish off the page
print <<<EOF
<p<$prev $direct_bar $next</p<
EOF;
print $article; // Put article onto page

print <<<EOF
<p<$prev $direct_bar $next</p>
EOF;?>


And that's it! You should now have three pages instead of one. This really helps to make it all look neat. This same thing can be done with MySQL or any other database just by selecting the article out of the database.

Enjoy!



Tutorial pages:
 1 Votes

You might also want to check these out:


Leave a Comment on "How To Put Your Articles Into Separate Pages"
You must be logged in to post a comment.

Link to This Tutorial Page!


GET OUR NEWSLETTERS