...

View Full Version : limiting text problem



paddyfields
07-24-2012, 08:10 PM
Hi, if you look at the attached picture this will make a lot more sense :)

I'm want the text to always be limited to two lines, but different sentences affect this regardless of the way i've limited the strings character count with the method below;


$var = $row['gigdescription'];
$varlength = strlen($var);
$limit = 140;
if ($varlength > $limit) {
$description = substr($var,0,$limit).'...';
}

I'm hoping someone has a novel idea of how I can achieve this?

Many thanks.
Pat.

Keleth
07-24-2012, 08:18 PM
Its one I've been tackling a while, and without picking a unispaced font, I don't think its possible.

paddyfields
07-24-2012, 08:22 PM
Hmm, that's a pain.

Thanks anyway.

paddyfields
07-24-2012, 08:38 PM
Even with a unispaced font I still seem to have the same problem? The only possible thing I can think of is making a div and hiding the overflow for anything past two lines (setting a height of say 30px) but this seems like a silly way to do it.

ahhh. so frustrating.

Fou-Lu
07-24-2012, 08:44 PM
You'll always have a problem.
This isn't a PHP issue though. The only way you can control it in PHP is to actually chop it at its given sizes. I can put a single linefeed all I want in there, which will make it accurately two lines of text, though the HTML control the sizing as appropriate to match the rulesets you've given it.

So this is more of an HTML issue and not that of PHP. If you check your source output, you should have a single linefeed separating the string. Now its up to HTML to render it properly, which may include the use of horizontal scroll bars.

Now since this is a rendering issue, which is never that of PHP, I'll move this to the HTML forum.


Actually you won't even have a linefeed as you've not specified one as such. You have specified a number of characters to chop at. So in PHP you have a single line of text.

paddyfields
07-24-2012, 08:50 PM
Cool, thanks for your help. I only posted this in the PHP forum incase there was a trick that could be done with substr, but clearly not. Hopefully I'll find an HTML solution.

I'm joking about the frustration as well, it's all fun and games. :thumbsup:

DrDOS
07-24-2012, 08:57 PM
If you need a nice looking monospace font, you can use Droid-sans Mono, it's a Google font and it's free, I think you can even link to it on the Google font site.

Will Bontrager
07-24-2012, 11:24 PM
Hi, if you look at the attached picture this will make a lot more sense :)

I'm want the text to always be limited to two lines, but different sentences affect this regardless of the way i've limited the strings character count with the method below;


$var = $row['gigdescription'];
$varlength = strlen($var);
$limit = 140;
if ($varlength > $limit) {
$description = substr($var,0,$limit).'...';
}

I'm hoping someone has a novel idea of how I can achieve this?

Many thanks.
Pat.

Perhaps this will work: Put the content in a div with a style specifying the specific height that would reveal only two lines and
overflow:hidden;

Anything over two lines will then be hidden.

Will

paddyfields
07-24-2012, 11:50 PM
Thanks. I did actually suggest this myself in an earlier post and have decided to do it this way, seems to do the job. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum