Re: Splitting at word count

From: Date: Thu, 01 Jan 1970 00:00:00 +0000
Subject: Re: Splitting at word count
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-36800@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? > We have a "news" section with an index page that shows the first 3 articles in our queue. These articles are limited to their first 29 words. We then add a link to the full article. You can view this live: http://www.ukc.ac.uk/news/index.php $article = fgets($fd, 8192) /* Full text of your article. We get it from a file using fgets($fd, 8192) */ /* remove tags if there are any */ $newscontent = strip_tags($article) ; $pattern = " " ; $arr = split($pattern, $newscontent, 50); $story .= ("<p>") ; for ($i = 0 ; $i < 29 ; $i++) { $story .= (" " . $arr[$i]) ; } $story .= (" (cont.) <a href=\"yourarticlefilename.html\">Full article</a></p>\n"); We use this PHP in the <HEAD> of our document, so whenever we want it to be published we just use <? echo $story ; ?> It may not be very elegant, but it does work fine! Hope it helps Jose Jose Casal-Gimenez <J.Casal@ukc.ac.uk> University Web Support Officer Communications & Development Office G17, The Registry, University of Kent, CT2 7NZ Tel: (01227) 823102

« previous php.general (#36800) next »