FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » mail function and wordwrap
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: mail function and wordwrap [message #172274 is a reply to message #172270] Tue, 08 February 2011 22:39 Go to previous message
P E Schoen is currently offline  P E Schoen
Messages: 86
Registered: January 2011
Karma:
Member
"Jerry Stuckle" wrote in message
news:iisdq8$3lo$3(at)news(dot)eternal-september(dot)org...

> I *know* how to do it, also. But I also *know* how to get
> people to help themselves!

This thread was helpful to me by revealing the existence of the wordwrap
function, which will be helpful to me. But what I'd like to be able to do is
also indent each line by a certain number of characters. I'm sure this can
be done by replacing all occurrences of the newline character with a newline
and the number of spaces desired, although it would also need to be inserted
at the start of the first line. I found a Perl script that does this:

# Find length of longest field name, for formatting; include space for
colon
my $maxlength= 0 ;
foreach (keys %in) {
$maxlength= length if length > $maxlength ;
}
$maxlength++ ;

foreach ('Full_Name', 'Email', 'Event_Title','Event_Date','Event_Time',
'Event_Description') {

# If a field has newlines, it's probably a block of text; indent it.
if ($in{$_}=~ /\n/) {
$in{$_}= "\n" . $in{$_} ;
$in{$_}=~ s/\n/\n /g ;
$in{$_}.= "\n" ;
}

# comma-separate multiple selections
$in{$_}=~ s/\0/, /g ;

# Print fields, aligning columns neatly
printf MAIL "%-${maxlength}s %s\n", "$_:", $in{$_} ;
}

I will try to rewrite this in PHP, and it may be a good learning experience
since I am not fluent with RegEx. But if there is a better way, I'd
appreciate some tips.

Thanks,

Paul
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: An extremely large hash lookup mechanism
Next Topic: Unexpected error in log: php_gd2.dll
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 10 13:38:39 GMT 2024

Total time taken to generate the page: 0.04984 seconds