Page 1 of 1

fitting <textbox> input into DDS fixed length fields

Posted: Wed Nov 05, 2008 7:26 am
by itp
I have an HTML textboox (say 60 columns * 5 lines = 300 characters) that I want to write to 5 X 60-character fields in a set of 5 X 60 fixed length character fields.

My first inclination was to substring 60 character increments of the returned text.

But this won't work because textboxes do some funky word wrapping and HTML sucks out extra spaces. Then I started to figure out last full word and add back extra spaces but that is getting messy.

Anyone have a better HTML/PHP approach too this?

(And don't tell me to change the field to VARCHAR(300) or something like that. This file is used by 50+ programs on a green screen application that is over 20 years old)

Re: fitting <textbox> input into DDS fixed length fields

Posted: Wed Nov 05, 2008 8:06 am
by lettie_dude
How about

Code: Select all

$string = wordwrap($string, 60);

Re: fitting <textbox> input into DDS fixed length fields

Posted: Sat Nov 08, 2008 9:17 am
by itp
thanks. that got me started
Here is what I put together...

Code: Select all

 
$maxlineLength =64;
$maxLines=8;
 
// replace "white spaces" with a single space
$comments = preg_replace('/\s+/', ' ', $comments) ;    
 
// break string into chunks of of 64 or less with wordwrap()
$comments = wordwrap($comments, $maxlineLength, '\n', TRUE) ;            
 
//  count number of lines
$countLines = substr_count ( $comments, "\n" ); 
 
// test to see if we have exceeded number of lines 
if($countLines>$maxLines)
{
    $errorMsg = "Sorry your string is too long";
}