Filling A Box -> The hard way :)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Filling A Box -> The hard way :)

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

set the overflow CSS property to hidden.
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Post 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?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

No
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Post 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!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

There is no native function, but if you happen to look through the threads from Useful Posts you may find something. :)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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 '...';
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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
Post Reply