Jump to content

Help with articles system, splitting to pages


CrazeD

Recommended Posts

I'm trying to make an articles system, where you put the article in a textarea and when you view the page PHP splits it into pages.

 

I know how to do pagination, but I'm not really sure how to go about splitting the article into pages the way I want. Just splitting into pages isn't a problem, however I'd like it to be split where specified. So far I have two ways to do that, one would be using Javascript to create multiple textarea's for each page section, and the other would be to insert, for example, {PAGE2} into the article where it would be split and have PHP parse it.

 

For either method, I'll probably still have {PAGE2} (or whatever) entered to be parsed by PHP.

 

The problem is, I don't really know how to parse a string and execute code if certain criteria is met.

 

If anyone understands what I'm trying to do, can you please help in any way?

 

Thanks.

Link to comment
Share on other sites

Its a pretty simple concept.

 

<?php

  $s = "this is page 1{newpage}this is page two{newpage}this is page three";

  $pages = explode('{newpage}',$s);
  if (isset($_GET['page'])) {
    if (count($pages) <= $_GET['page']) {
      echo $pages[$_GET['page']-1];
    } else {
      echo "Page does not exist";
    }
  } else {
    echo $pages[0];
  }

  echo "<a href='?page=1'>page 1</a><br />";
  echo "<a href='?page=2'>page 2</a><br />";
  echo "<a href='?page=3'>page 3</a><br />";

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.