Results 1 to 4 of 4

Thread: split html for pagination

  1. #1
    Join Date
    Jul 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default split html for pagination

    I have set up a nice javascript pagination system using explode() with a pre-set seperator. This divides the root file by 'item' (an item comprises a title and sub-text)

    For some pages the items are quite long and I would like the option to have a page split according to text length. The pagination script requires an array so I have been playing with:
    $split_text=chunk_split($str,22,'|');
    $split_array=explode('|',$split_text);

    The only problem here is it ignores both words and html tags.
    The only word-related php I can find is: str_word_count and this also ignores html tags.

    I guess I could explode using a (full) stop but this snags if the page includes a path reference - eg. img src=../images/pot.gif
    Ditto splitting by space.
    In short, there seems too many if{} else{} permutations to try this approach.

    So, how to split (or explode) a bunch of html in relation the actual text?
    Any suggestions or solutions would be much appreciated.

    cheers - arfa

  2. #2
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

  3. #3
    Join Date
    Jul 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default splitt html

    thanks for the reply but I am splitting html - not sql data

    basically it is all in a simple text file
    include 'text_file';

    split_explode
    print paginated data - if only )

    I imagine this issue is not exclusive to me and that there is a standard solution floating about somewhere. Yes?

    cheers - arfa

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    define('WORDS_PER_PAGE', 22);
    
    function getPage($file, $page) {
      $fc = file_get_contents('text_file');
      $firstword = WORDS_PER_PAGE * ($page - 1);
      $lastword = WORDS_PER_PAGE * $page;
      $words = explode(' ', $fc);
      $pgc = '';
      for($i = $firstword; $i < count($words) && $i <= $lastword; ++$i)
        $pgc .= ' ' . $words[$i];
      return $pgc;
    }
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh 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
  •