Jump to content


Photo

*SOLVED* Create a blurb from a news article


  • Please log in to reply
3 replies to this topic

#1 Flukey

Flukey
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 10 May 2006 - 10:55 PM

Hey guys,

I've created a news content management system. I want to list the articles BUT i want to list only part of the article e.g. the first 100 words etc... and then a link to the full article.

This is the only thing i'm stuck on doing.

Thanks very much


Jamie :)

#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 10 May 2006 - 11:24 PM


##########################################
# This little function will take a string, truncate it to a specific length, make sure it is not truncated in 
#  the middle of a word and add three trailing periods.
##########################################

Function display_teaser($article,$display_length) {
    if(strlen($article)>$display_length) {
      $display_portion = substr($article,0,$display_length);
    } else {
      $display_portion = $article;
    }
      $true=0;
      while ($true < 1) {
        if(substr($display_portion, -1) != " ") {
            $display_portion = substr($display_portion, 0, -1);
        }else{
            $true = 1;
        }
      }
    $display_portion = $display_portion . "...";
    return $display_portion;
}

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 KrisNz

KrisNz
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts
  • LocationAuckland, New Zealand

Posted 11 May 2006 - 12:04 AM

This question seems to come up fairly frequently. If you wanted 100 words just change 21 to 101.

$string = "here is a string that has a few words in it and is fairly long and boring and needs to be trimmed
down so that it doesnt keep going and going and going and going";
$a = explode(" ",$string,21);
array_pop($a);
$output = implode(" ",$a);
echo $output."...";


#4 Flukey

Flukey
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 11 May 2006 - 09:43 AM

Cheers guys. I'll post back later when i haveit implemented.

Thanks muchly.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users