SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML News feed & displaying first line of news as a summary

    Hi Guys,

    Need your advice to solve my problem.

    Background -
    I am adding news feed on a website. Have stored those news feeds on local database using file read & loading xml into dom object.
    News feeds do not have summary. Content get stored in $content using
    Code:
    $ContentsNd = xpath_eval($temp, "/Contents");
    $content = $ContentsNd->nodeset[0]->get_content();
    On latest news page I want to put summary & heading(title) of that article.
    But as I do not have summary for news article in xml feed, I am using following code to add few lines from content -
    Code:
    strlen(stripslashes($d->Contents))>160)?substr(stripslashes($d->Contents),0,160):stripslashes($d->Contents)
    Problem - It sometimes ends on one character which does not look good,
    so i was thinking its better way to put first line of each article as a summary.
    But dont have any idea about any built in function which I can use to do this.
    So pls help me. Thanks in advance for your time.

    Regards

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,044
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)
    Yes, truncating a string at a set length can have undesirable results. You can always use strrpos() "string reverse position" to find the first "space" backwards from a certain length and then use substr() "substring" to get an excerpt terminating at that space.


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
  •