Re: Splitting at word count
| From: | Richard Lynch | Date: | Fri, 26 Jan 2001 10:53:36 +0000 |
| Subject: | Re: Splitting at word count | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-36768@lists.php.net to get a copy of this message | ||
> I'm doing a page where the front page will show "news" stories. What I'd
> like is if the story is longer than X words/chars/etc, the index page will
> show the first X words, then a link for the full story.
>
> Does anyone have a good idea on how to split after a certain number of
> words?
<?php
if (strlen($story) > 50){
$start = 50;
#You may want to add "\t" and "-" and suchlike as "break"
chars:
while (isset($story[$start]) && $story[$start] != ' ' &&
$story[$start] != "\n")){
$start++;
}
echo substr($story, 0, $start);
#We may have managed to squeeze out the last word...
if ($start < strlen($story)){
echo "<A HREF=fullstory.php?story_id=$story_id>M O R E</A>";
}
}
else{
echo $story;
}
?>
--
Visit the Zend Store at http://www.zend.com/store/
Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm