SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Aug 2001
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Split existing articles into pages for WAP

    WAP-enabled phones can only handle tiny cards, so I need to break my articles into pages of about 500 characters each, adding "next" and "prevoius" links. I found many tips on this forum, recommending to use [pagebreak] tags. Unfortunately, I can't do it, because I have a large archive of existing articles, and besides, it would be painful to insert all those tags every 500 characters. At this point, I simply limit the articles by the first 500 characters:

    PHP Code:
    $limit 500;
    if (
    strlen($article) > $limit) {
    echo 
    "<p>".substr("$article"0$limit)."...</p>\n";
    } else echo 
    "<p>$article</p>\n"
    How do I display the rest? Thanks for your feedback!

  2. #2
    SitePoint Wizard Crowe's Avatar
    Join Date
    Nov 2001
    Location
    Huntsville
    Posts
    1,117
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I have this working on my site. Here is the basic code I use:

    PHP Code:
    $query="SELECT * FROM table WHERE id='$viewid' limit 1";      
    $results=mysql_query($query);        

    if(
    $myrow=mysql_fetch_array($viewresults))      {        
    do {

    // Put your output here
    $text $myrow["text"];

    // Start Paging Code

    // Don't edit this
    $placeholder=0;

    // Word Limit
    $wordCount=2000;


    for(
    $c=0;$c<(strlen($text)/$wordCount);$c++)

    {
            
    $newtext[$c]=substr($text,$placeholder,$wordCount+strpos(substr($text,$wordCount+$placeholder),"\n"));
            
    $placeholder=$placeholder+strlen($newtext[$c]);
    }

    for(
    $c=0;$c<sizeof($newtext);$c++)

    // If no page specified, default to the
    // first page ($page = 0)
    if (!isset($page)) $page 0;

    $articletext=$newtext[$page];

    echo( 
    "<p>$articletext</p>" );

    echo 
    "<table width=\"100%\"><tr>";

    // Select the page we want

    if ($page != 0) {
      
    $prevpage $page 1;
      echo 
    "<td align=\"left\" width=\"50%\"><A HREF=\"$PHP_SELF?viewid=$viewid&page=$prevpage\"><-- Prev Page</A></td>";
    }


    if (
    $page count($newtext) - 1) {
      
    $nextpage $page 1;
      echo 
    "<td align=\"right\" width=\"50%\"><A HREF=\"$PHP_SELF?viewid=$viewid&page=$nextpage\"> Next Page --></A></td>";
    }

    echo 
    "</tr></table>";
    // End Paging Code


            
    } while ($myrow=mysql_fetch_array($results)); 


    There might be a quicker way, but this way works for me. You can take a look at it working here: http://www.lit.org/reader.php?viewid=4748

    I haven't fully tested it for bugs, but it *seems* to be working okay.
    Chrispian H. Burks
    Nothing To Say

  3. #3
    SitePoint Member
    Join Date
    Aug 2001
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! I'll try it.

  4. #4
    SitePoint Member
    Join Date
    Aug 2001
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It works, but on your site every new page starts nicely with a new paragraph, while the above script breaks them in the middle of a word.

  5. #5
    SitePoint Wizard Crowe's Avatar
    Join Date
    Nov 2001
    Location
    Huntsville
    Posts
    1,117
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It seems my code is kinda bugy For example, check out this poem on my site: http://www.lit.org/reader.php?viewid=4747

    Maybe someone could help us out here?
    Chrispian H. Burks
    Nothing To Say

  6. #6
    SitePoint Addict zoordaan's Avatar
    Join Date
    Feb 2001
    Location
    NYC/Texas
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Take a look at the wordwrap function : http://us2.php.net/manual/en/function.wordwrap.php


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
  •