Click to See Complete Forum and Search --> : Showing only the first few words
nuthead
08-17-2003, 03:41 AM
Im wanting to show only the first 10 words from a string, as like a headline on a news site but can't for the life of me find a function to do this other than splitting the sentence up into an array and then sticking the first 10 parts of the array into a new string but that seems a bit too long-winded. Is there any function out there that does what i need?
Quasibobo
08-17-2003, 04:11 AM
I wrote this a long time a go:
$number_of = count(preg_split('/\s+/', $row['tablefield']));
$max=25;
if ($number_of <= $max)
{
print($row['tablefield']);
}
else
{
$string = explode(" ", $row['tablefield']);
$synopsis ="";
for ($i=0;$i<$max;$i++)
{
$synopsis = $synopsis . " " . $string[$i];
}
print $synopsis.".......";
}