Page 1 of 1

Filling A Box -> The hard way :)

Posted: Sun Aug 27, 2006 1:56 pm
by seodevhead
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.

Posted: Sun Aug 27, 2006 2:00 pm
by feyd
set the overflow CSS property to hidden.

Posted: Sun Aug 27, 2006 2:05 pm
by seodevhead
feyd wrote:set the overflow CSS property to hidden.
Could this cause problems with Search Engines thinking I am trying to hide text if indeed I get some overflow?

Posted: Sun Aug 27, 2006 2:06 pm
by Benjamin
No

Posted: Sun Aug 27, 2006 2:11 pm
by seodevhead
Is there a function like strlen() that will allow me to output a certain number of words as opposed to a certain number of characters? I think this would work a lot better for me, but I can't seem to find such a function. Thanks!

Posted: Sun Aug 27, 2006 2:15 pm
by feyd
There is no native function, but if you happen to look through the threads from Useful Posts you may find something. :)

Posted: Sun Aug 27, 2006 2:15 pm
by Benjamin
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 '...';

Posted: Sun Aug 27, 2006 3:24 pm
by Ollie Saunders

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