whoaa..
way cool guys...
guess somebody has been dippin in the news excerpt businees eh
okie dokie...
i've been thru all the code..
and you guys rawk... totally..
so here to sums up the winner,
plus with some personal comment...
the second runner up..
$news = "Within the current incarnation of (X)HTML tables are the building blocks to well organized and attractive designs. <br>";
$news .= "They allow the developer an incredible amount of control over the visual representation of information and graphics. <br>";
$news .= "However they come with a catch, they are an absolute headache to write into your PHP code. <br>";
$news .= "Thankfully there is a solution: the PEAR HTML_Table class.";
$synop = substr($news,0,125);
$news_array = explode(' ',$synop);
$words = count($news_array) - 1;
for ($i=0; $i<$words; $i++) {
$excerpt .= " " . $news_array[$i];
}
echo strip_tags($excerpt) . "....";
Comment: the best code if u are paid per line..
and probably the most simplest logic ever..
i love this one.. its a classic...
although i did a lil' modifications on it
but as weedpacket said, it can be adapted to read lines from files
and by far the best in performance speed...
coz i think it read only the first 125 character..
this is truely amazing..
and the winner is
$news = "Within the current incarnation of (X)HTML tables are the building blocks to well organized and attractive designs. <br>";
$news .= "They allow the developer an incredible amount of control over the visual representation of information and graphics. <br>";
$news .= "However they come with a catch, they are an absolute headache to write into your PHP code. <br>";
$news .= "Thankfully there is a solution: the PEAR HTML_Table class.";
$wordcount = 20;
preg_match('/^\s*(\S+\s+){' . $wordcount . '}/', $news, $out);
echo strip_tags($out[0]) . "...";
Comment: By far, the most simplest, yet technically great..
well, i'd say this would be the quickest way to do it,
i dont know if this method superseeds the above for speed
but i truely love this one too...
and the rest of the code..
well, using strtok i believe it tokenize the string
into its individual words by using the space character as the token
so by theory, i guess if there is 1000 words,
it will tokenize every single words, hence performance degration
but please correct me if i'm wrong eh weedpacket
preg_split().. hmm.. i know it can somehow split text,
but ya need some sort of pattern... and i guess this would do too
lemme see...
$wordsmax = 20;
$keywords = preg_split ("/[\s,]+/", $news);
for ($i=0; $i<$wordsmax; $i++) {
$excerpt .= " " . $keywords[$i];
}
echo $excerpt . "...";
hey... what did cha know..
it works...
nice one 😃
anyway...
just wondering..
with so much method for one objectives..
how do i know which code take the least time, the less resource,
and the most simplest way to execute???
to sum it all up...
u guys are cool... totally... 😃 😃
thanks a lot guys!!!!
and now.. its time to click the resolved buttons 😃
cheers;
-jassh