01<?php 02 03functionsummarize($paragraph,$limit,$link) 04{ 05$text=''; 06$words=0; 07$tok=strtok($paragraph,' '); 08while($tok) 09{ 10$text.="$tok"; 11$words++; 12if(($words>=$limit)&&((substr($tok,-1)=='!')||(substr($tok,-1)=='.'))) 13break; 14$tok=strtok(' '); 15} 16$text.=' '.$link; 17returnltrim($text); 18} 19 20// use like this 21$example='Heres some code to extract the first part of a long paragraph, e.g. to use as a summary. 22Starting at the beginning of the paragraph it gets as many complete sentences 23as are necessary to contain $limit words. 24For example, with $limit at 20 it would return the first two sentences 25of the paragraph e reading right now 26(the first 20 words plus the rest of the sentence in which the limit was hit)'; 27 28$link='<a href="#">read more</a>'; 29 30echo'<p>'.summarize($example,5,$link).'</p>'; 31 32?>