Only want a few lines of description

I am needing to only have like 5 lines of the item description shown on a page. I have looked and I cannot find the answer anywhere.

my html looks like this

<p><?php echo $desc; ?></p>

You can use substr to get a certain amount of characters…

Are your item descriptions new lines done by \n? How do you determine the new lines?

I dont have anything determine new lines. I am letting the data get pulled from the table. I am new to php (only been doing it about a month) and I am still learning.

Here you can see what I have. I would like the wording to be the same length as the image if possible.

http://puu.sh/cZJ5C/ea939babeb.png

Ok hypotheticallly let’s imagine this. We somehow figure out the code to only show up to “for different size.”

What if a user resizes the text? PHP can’t handle that.

So you’ll need to figure out if you want to have just a standard amount of text and ignore what happens if users resize text, or do this in Javascript to hwere it can (maybe?) update on the fly.

1 Like

I would just use the standard amount of text. If the user resizes it then I would understand it would be bigger and I would hope the user would to.

Another users “standard” might be bigger/smaller than YOURS though. Ignoring the resize factor. They might just have a bigger standard (they can set it to whatever they want)

ok, so what would your suggestion be to get this working? Could you please send me to where I can learn about it and implement it?

Yea like @RyanReese said, you can’t really do this in PHP outside of just using substr. PHP has no knowledge of the browser, it just spits stuff out.

You might be able to do it with a combination of floats, overflow, and CSS ellipses. But that would probably be spotty. If you really need it to be the same height as the image no matter how crazy the image dimensions are, then you can do it with JavaScript by recursively checking if the image/text wrapping div is taller than the image and just keep removing words until it isn’t anymore.

The image size will be exactly the same on the page.

Can anyone point me in the right direction so I can learn about it and get it going on my site.

Thanks

You haven’t told us how you want this.We’ve pointed out variables that puts question into what you want. How do you want to handle the user resize? Your best bet is to use substr, but the better route would be to open a thread in the Javascript section and see what they recommend in terms of doing this. PHP is not suited for this.

Ok thank you, I will open another thread in the javascript section.

I appreciate everyones time and input on this.

This… isnt -quite- true. Because PHP can render text into an image (via things like GD), it CAN know how wide things will be in the browser - by defining it.

That said, PHP is not really the right tool for handling it. Maybe just clever use of HTML and CSS.

That’s only for single-line use though, from what the article is saying.

Continued