tomazos has asked for the wisdom of the Perl Monks concerning the following question:
# pass in multi-paragraph English text sub calculate_rows_from_content($) { my ($content) = @_; # hard wrap $content =~ s/([^\n]{80})/$1\n/g; # count newlines + 3 my $rows = 3; $rows++ while ($blurb =~ /\n/g); return $rows; }
Its pretty good, but not perfect (nor will it ever be without testing the user agent because different browsers hide and show the scrollbar when the content fits, changing the real width, sigh).
Wondering if anyone has a more accurate one? This one doesn't take into account whole words getting wrapped - and most likely a bunch of other things.
-Andrew.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Estimating height of TEXTAREA from content
by Your Mother (Archbishop) on Jul 25, 2005 at 03:22 UTC | |
|
Re: Estimating height of TEXTAREA from content
by merlyn (Sage) on Jul 25, 2005 at 01:50 UTC | |
by tomazos (Deacon) on Jul 25, 2005 at 02:43 UTC | |
by simonm (Vicar) on Jul 25, 2005 at 05:33 UTC | |
by Your Mother (Archbishop) on Jul 25, 2005 at 06:39 UTC | |
by tomazos (Deacon) on Jul 25, 2005 at 15:58 UTC | |
by merlyn (Sage) on Jul 25, 2005 at 03:09 UTC | |
by tomazos (Deacon) on Jul 25, 2005 at 06:05 UTC | |
by merlyn (Sage) on Jul 25, 2005 at 14:05 UTC | |
|