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.

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 />";

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.