Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Dec 2010
    Location
    London
    Posts
    333
    Thanks
    63
    Thanked 11 Times in 11 Posts

    limiting text problem

    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;

    PHP Code:
    $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.
    Attached Thumbnails Attached Thumbnails limiting text problem-picture-4.png  

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,535
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Its one I've been tackling a while, and without picking a unispaced font, I don't think its possible.

  • #3
    Regular Coder
    Join Date
    Dec 2010
    Location
    London
    Posts
    333
    Thanks
    63
    Thanked 11 Times in 11 Posts
    Hmm, that's a pain.

    Thanks anyway.

  • #4
    Regular Coder
    Join Date
    Dec 2010
    Location
    London
    Posts
    333
    Thanks
    63
    Thanked 11 Times in 11 Posts
    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.

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

    Edit:
    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.

  • #6
    Regular Coder
    Join Date
    Dec 2010
    Location
    London
    Posts
    333
    Thanks
    63
    Thanked 11 Times in 11 Posts
    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.

  • #7
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,911
    Thanks
    15
    Thanked 227 Times in 227 Posts
    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.

  • #8
    Regular Coder
    Join Date
    Jun 2012
    Location
    Near Chicago, USA
    Posts
    123
    Thanks
    7
    Thanked 19 Times in 19 Posts
    Quote Originally Posted by paddyfields View Post
    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;

    PHP Code:
    $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
    Code:
    overflow:hidden;
    Anything over two lines will then be hidden.

    Will
    Last edited by Will Bontrager; 07-24-2012 at 11:25 PM. Reason: clarification
    Numerology API for apps - Facebook, iPad, mobile phones. No charge to use API. [info]

  • #9
    Regular Coder
    Join Date
    Dec 2010
    Location
    London
    Posts
    333
    Thanks
    63
    Thanked 11 Times in 11 Posts
    Thanks. I did actually suggest this myself in an earlier post and have decided to do it this way, seems to do the job.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •