fitting <textbox> input into DDS fixed length fields

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
itp
Forum Commoner
Posts: 67
Joined: Fri Jun 15, 2007 6:50 am

fitting <textbox> input into DDS fixed length fields

Post 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)
lettie_dude
Forum Commoner
Posts: 65
Joined: Thu Dec 07, 2006 10:10 am

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

Post by lettie_dude »

How about

Code: Select all

$string = wordwrap($string, 60);
itp
Forum Commoner
Posts: 67
Joined: Fri Jun 15, 2007 6:50 am

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

Post 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";
}
 
 
Post Reply