SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Hybrid View

  1. #1
    SitePoint Addict Chris Roane's Avatar
    Join Date
    Jul 1999
    Location
    Helena, MT
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I am refering to Kevin's tutorial.

    I can use the text [PAGEBREAK] in each article to split the page up into different pages. But instead of using the "Continue to Next Page" text, I want to be able to specify what text to use in each link to the next page.

    In a previous post, Karl posted the following:

    ----------------------------------------
    Like Chris said you can use [PAGEBREAK] for the page breaks, if you want to give each page a different name to page 1, page 2 etc. then you could use [PAGEBREAK=NameOfNextPage] and use a regular expression to split the page up and give you the name of the next page.
    ----------------------------------------

    Can someone tell me what a regular expression is and how I am supposed to use that to do what I am wanting to do? I already got it to split up the article into different pages.

    Thanks!

    Chris Roane

    ------------------
    Web Services: DevStorm | Intersurge
    Web Tools: Web Site Resource | Free Web Site Tools

    [This message has been edited by wsresource (edited August 04, 2000).]

    [This message has been edited by wsresource (edited August 04, 2000).]

  2. #2
    ********* Addict
    Join Date
    Apr 2000
    Location
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've done just that. But instead of typing just [PAGEBREAK] you will also have to type something like [NEXTPAGE=Text that links to next page] and it works without a hitch. Here's the code I have used:
    Code:
    $nextID = $pid + 1;
    $articleText = eregi_replace("\[NEXTPAGE=([-_./a-zA-Z0-9 !&%#?,'=:~\"]+)]","&lt;A HREF=\"/article.php?aid=$aid&pid=$nextID&cid=$cid\">\\1</A><FONT COLOR=\"red\">>></FONT>",$articleText);
    Maybe there was a smaller version of my regular expression but this one worked for me. If it ain't broke, don't fix it.


    [Edited by kyank on 11-07-2000 at 12:14 AM]

  3. #3
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Looks good to me, Pedro! It's incredibly rewarding to see people expanding on the code I've presented. It really convinces me that I've provided you with new skills, rather than just code fragments for you to cut and paste!

    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!

  4. #4
    Who Me? JeremyL's Avatar
    Join Date
    Dec 1999
    Location
    Dallas, TX
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thats cool.

    Now how do I also add a menu at the bottom that looks like "<<Back 1 2 3 4 5 6 7 Next>>" so that people can use these links to jump from page 1 to page 5 without having to load 5 pages?

    ------------------
    Jeremy Luebke --&gt; jeremy@coolresources.com
    CoolResources.com --&gt; Part of the W3Nation Network

    [Edited by kyank on 11-07-2000 at 12:15 AM]

  5. #5
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HEY! What's wrong with cut-and-paste?


    ------------------
    Chris Bowyer – chris@mycoding.com
    MyCoding.com: Visit for Launch Notification!
    DomainMailings.com: Who Says All The Good Ones Are Taken?
    MovieForums.com: Talk About Your Favorite Flicks!

    [Edited by kyank on 09-16-2000 at 10:14 AM]

  6. #6
    ********* Addict
    Join Date
    Apr 2000
    Location
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You've experienced the same problem as me! No line breaks! It's annoying, eh?

    [Edited by kyank on 09-16-2000 at 10:14 AM]

  7. #7
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Now how do I also add a menu at the bottom that looks like "<<Back 1 2 3 4 5 6 7 Next>>" so that people can use these links to jump from page 1 to page 5 without having to load 5 pages?
    You can determine the number of pages by using split() to split the text of your article (or whatever) into an array, each element of which contains the contents of a single page.

    Code:
    // $fulltext was fetched from the DB.
    
    $regexp = "\[NEXTPAGE=([-_./a-zA-Z0-9 !&%#?,'=:~\"]+)]";
    $numpages = count(split($regexp,$fulltext));
    The code to create the list of links should then be pretty straightforward.


    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!

    [Edited by kyank on 11-07-2000 at 12:15 AM]

  8. #8
    Almeaty Member
    Join Date
    Jul 2000
    Location
    Nowhere
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Uhhm... maybe it's because I'm not as good-thinking as others but yet I don't know how to display the text for the second page or any other pages.

    I already split up the full text and also the page numbers with their corresponding page ID is there. Only the content is missing

    please help...

  9. #9
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Okay, say we want to view page 5. Thus, $pid is set to 4.

    Code:
    // $pid = 4 indicates we want page 5.
    // $fulltext was fetched from the DB.
    
    $regexp = "\[NEXTPAGE=([-_./a-zA-Z0-9 !&%#?,'=:~\"]+)]";
    $pages = split($regexp,$fulltext);
    $numpages = count($pages);
    $pagecontent = $pages[$pid];
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  10. #10
    Almeaty Member
    Join Date
    Jul 2000
    Location
    Nowhere
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow, thanks!! Thank you so much!

    I've made some changes, to make things easier (not sure, if better)

    Code:
    // $content was fetched earlier
    // insert "PAGEBREAK" if you want to start a new page
    
    $fulltext = split( "PAGEBREAK", $content );
    
    if ( !$pid )
      $pid = '1';
    
    $numpages = count( split( "PAGEBREAK", $content ) );
    
    // only display "Page [int]" if there are more than one pages
    if ( $numpages > 1 )
    {
      echo "<b><i>Page " . $pid . "</i></b>\n";
    }
    
    echo $fulltext[$pid-1];
    
    if ( $numpages > 1 )
    {
      echo "<table><tr><td bgcolor=#eeeeee align=center>";
      for ( $i=1; $i<$numpages+1; $i++ )
      {
        echo "<b><a href=\"?id=" . $id . "&pid=" . $i . "\">" . $i . "</a></b> ";
      }
    }

  11. #11
    SitePoint Enthusiast
    Join Date
    Nov 1999
    Location
    Singapore
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, sorry about this, but I'm confused even more.

    What I think I understand:

    $regexp = "\[NEXTPAGE=([-_./a-zA-Z0-9 !&%#?,'=:~\"]+)]";
    $numpages = count(split($regexp,$fulltext));

    Am I correct in saying that what the lines above do is this: It looks for the "[NEXTPAGE]", while $numpages counts how many [NEXTPAGE]s there are, ie how many pages there are. It then seperates $fulltext into arrays with one page in each array. Am I wrong?

    Secondly, how do I go from here to making the list of links?
    I didnt really understand the bits later on in the thread.

    Adolescent Adulthood - Learn All ABout Flirting, Dating And Dumping.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •