#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    5
    Rep Power
    0
    I am in the process of making a "News Section" for my site. What I am trying to figure outis this; is there a way to have PHP count the amount of characters in the "article", and automatically create an "abstract" that is displayed on the front page?

    Any insights wold be greatly appreciated.
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    18
    First you have to determine the maximum length you'd like for the abstract. Then, using substr(), you can grab that much of the string. Of course, this might be the middle of the word so you can use strrpos() to get the position of the last space. Then use substr() again to grab everything until that space.

    function Abstract($text,$length)
    {
    $text=substr($text,0,$length);
    $lastspacepos=(strrpos($text,' ')-1);
    // -1 because we don't want to return the space as well
    return substr($text,0,$lastspacepos);
    }

    You can call this like:

    $abstract=Abstract($full_story_text,255);

    HTH
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    5
    Rep Power
    0
    Thanks! It worked beautifully, with the exception that the "-1" actually chopped of the last letter in the word. When removed though, it works like a charm.

    You rule.

Similar Threads

  1. Making updated news section
    By popcop in forum PHP Development
    Replies: 6
    Last Post: January 30th, 2004, 10:11 PM
  2. Parsing News Feeds
    By jessenco in forum XML Programming
    Replies: 1
    Last Post: January 21st, 2004, 02:13 AM
  3. Parsing News Feeds
    By jessenco in forum HTML Programming
    Replies: 0
    Last Post: January 19th, 2004, 01:54 PM
  4. dynamic go back button?
    By Tom Mucciolo in forum HTML Programming
    Replies: 20
    Last Post: October 21st, 2003, 09:43 PM

IMN logo majestic logo threadwatch logo seochat tools logo