Filling A Box -> The hard way :)
Moderator: General Moderators
- seodevhead
- Forum Regular
- Posts: 705
- Joined: Sat Oct 08, 2005 8:18 pm
- Location: Windermere, FL
Filling A Box -> The hard way :)
I have a dynamic web application that allows people to post short stories. And the page that lists all the short stories from all the different users is to show a short exerpt of each short story.
Because I want a certain look of this specific page, I want each "exerpt" to be within a bordered box that is exactly a certain pixeled height. Obviously if I do a strlen($excerpt) output, it will always differ and I won't be able to, with certainty, to fill those fixed-height bordered boxes.
So is there a way with either CSS, PHP, etc.. to allow me to use an excerpt of the short stories and completely fill the containing fixed-height box without having any overflow or without the excerpt coming out too short and not filling the entire bordered box? And just FYI, at the bottom of the bordered boxes is a link that says "continue reading..." that links to the full story.
Any help and ideas on this matter would be greatly appreciated. Thanks so much.
Because I want a certain look of this specific page, I want each "exerpt" to be within a bordered box that is exactly a certain pixeled height. Obviously if I do a strlen($excerpt) output, it will always differ and I won't be able to, with certainty, to fill those fixed-height bordered boxes.
So is there a way with either CSS, PHP, etc.. to allow me to use an excerpt of the short stories and completely fill the containing fixed-height box without having any overflow or without the excerpt coming out too short and not filling the entire bordered box? And just FYI, at the bottom of the bordered boxes is a link that says "continue reading..." that links to the full story.
Any help and ideas on this matter would be greatly appreciated. Thanks so much.
- seodevhead
- Forum Regular
- Posts: 705
- Joined: Sat Oct 08, 2005 8:18 pm
- Location: Windermere, FL
- seodevhead
- Forum Regular
- Posts: 705
- Joined: Sat Oct 08, 2005 8:18 pm
- Location: Windermere, FL
Something like this if you don't want to use substr..
Code: Select all
$count = 40;
$words = 'This is the text blah blah';
$words = explode(" ", $words);
if (count($words) < $count) {
$count = count($words);
}
for ($i = 0; $i <= $count; $i++)
{
echo $words[$i];
}
echo '...';- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Code: Select all
$value = 'This is a string with a
couple
of words';
$splits = preg_split('/\s+/', $value, null, PREG_SPLIT_OFFSET_CAPTURE);
for ($i=0,$j=count($splits); $i<$j; $i++) {
echo 'The position of word ' . $i . ' is ' . $splits[$i][1] . '<br />';
}Code: Select all
The position of the word 0 is 0
The position of word 1 is 5
The position of word 2 is 8
The position of word 3 is 12
The position of word 4 is 19
The position of word 5 is 24
The position of word 6 is 27
The position of word 7 is 34
The position of word 8 is 46