Re: [PHP] Splitting at word count

2001-01-26 Thread Richard Lynch

 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_idM 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]




Re: [PHP] Splitting at word count

2001-01-26 Thread Jose Casal-Gimenez


 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 [EMAIL PROTECTED]
University Web Support Officer
Communications  Development Office
G17, The Registry, University of Kent, CT2 7NZ
Tel: (01227) 823102


-- 
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]




RE: [PHP] Splitting at word count

2001-01-26 Thread Dustin Butler

 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?
 
 Thanks,
 Wade

Put the story in an array and grab the first x elements?  Say you want 50
words you would do:

$num_of_words = 50;
$story_array = explode(" ", $story, $num_of_words);
$story_preview = implode(" ", array_pop($story));

Assuming all words are seperated by a space.

Dustin


-- 
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]




[PHP] Splitting at word count

2001-01-25 Thread H. Wade Minter

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

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?

Thanks,
Wade
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE6cIdgX5y4ZKLK2pMRAjOoAJ0RD43TCH7yVTLKhVjtsJ2mr/ZLMgCgmcz0
QHiQipt8ngHq7dnVdiQeHXY=
=PwwQ
-END PGP SIGNATURE-


-- 
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]