smc Posted March 3, 2007 Share Posted March 3, 2007 Hey everyone, Basically I have an article in a Database and I would like it to display in an HTML table but I only want it to show up to 5 lines. I'm not sure how I can accomplish this. Any help would be greatly appreciated! Thanks!! Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted March 3, 2007 Share Posted March 3, 2007 First of all, how many words can fit on each line? It would probably be easier if you chose an amount of words/characters that you wanted to display that would equal about 5 lines. Not sure if that is what you want though. Quote Link to comment Share on other sites More sharing options...
smc Posted March 3, 2007 Author Share Posted March 3, 2007 Well it's difficult because the length of a word or amount of characters can vary. I can say 5 words and have "okay okay okay okay okay" but two words like "superflouous language and vocabulary yay" which obviously will equal the same characters but much longer for the latter Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 3, 2007 Share Posted March 3, 2007 You could use css to hide extra lines by using line height, em measurements and overflow: hidden Quote Link to comment Share on other sites More sharing options...
smc Posted March 3, 2007 Author Share Posted March 3, 2007 You could use css to hide extra lines by using line height, em measurements and overflow: hidden Could you clarify? I'm unfarmilar with that particular CSS function Quote Link to comment Share on other sites More sharing options...
JBS103 Posted March 3, 2007 Share Posted March 3, 2007 CSS is just a way to style and format the web-page, so you would be going outside the realm of PHP. However, getting a basic grasp of CSS is very easy. Quote Link to comment Share on other sites More sharing options...
smc Posted March 3, 2007 Author Share Posted March 3, 2007 I know CSS I'm just confused on that line-height function. Not sure how to limit a TD to X amount of lines Quote Link to comment Share on other sites More sharing options...
JBS103 Posted March 3, 2007 Share Posted March 3, 2007 I know CSS I'm just confused on that line-height function. Not sure how to limit a TD to X amount of lines Sorry, I miss read ya. I apologize. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 3, 2007 Share Posted March 3, 2007 You could use css to hide extra lines by using line height, em measurements and overflow: hidden I'd agree if most of the items were about 5 lines in size and you just want to suppress the odd rogue that is longer. In this case, where the items are articles, then it is a waste of bandwidth to send 50 or more lines, say, only to have 45+ hidden. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 3, 2007 Share Posted March 3, 2007 Try this <?php $article = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nulla lacinia justo at velit. Nunc porttitor nisl porta mi. Curabitur sollicitudin purus vel felis. Maecenas nunc. Nulla facilisi. Integer vel ante sit amet ipsum consequat facilisis. Suspendisse hendrerit urna vel erat. Quisque auctor, erat nec ullamcorper sollicitudin, wisi leo hendrerit nisl, eu auctor turpis justo quis justo. Proin arcu metus, commodo quis, tincidunt varius, fermentum eget, lectus. Ut tellus. Sed nec dolor. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam sed magna."; // set the line length required, say 50 chars $len = 50; // break text every $len characters $lines = explode("\n", wordwrap($article, $len)); // get first 5 lines and add <br/> tags $toPrint = join('<br/>', array_slice($lines, 0, 5)); echo $toPrint; ?> Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted March 3, 2007 Share Posted March 3, 2007 You make me sick Barand xP -sarcastic- I hope one day to be as good of a coder as you. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 4, 2007 Share Posted March 4, 2007 Thanks. I've been in this game since 1968 (one language or another) so I hope I've picked up something in that time Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.