> 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



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to