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
Switch to threaded view of this topic Create a new topic Submit Reply
mail function and wordwrap [message #172255] Tue, 08 February 2011 13:19 Go to next message
me is currently offline  me
Messages: 192
Registered: September 2010
Karma: 0
Senior Member
I have looked through php.net (and googled) without finding an example
of this particular scenario.

If the message is the result of:

$msg = "A very long sentence\n";
$msg .= "A short sentence\n"; // less than 70 characters
$msg .= "Another short sentence\n"; // less than 70 characters
$msg .= "Another very long sentence";

$msg = wordwrap($msg, 70);

Does wordwrap only act on the longer individual strings? Will the short
strings appear on lines of their own?

In other words, will the formatting (\n) in each string taken separately
override the overall wordwrap?

Thank you,

Bill B
Re: mail function and wordwrap [message #172256 is a reply to message #172255] Tue, 08 February 2011 13:34 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 2/8/2011 8:19 AM, Bill B wrote:
> I have looked through php.net (and googled) without finding an example
> of this particular scenario.
>
> If the message is the result of:
>
> $msg = "A very long sentence\n";
> $msg .= "A short sentence\n"; // less than 70 characters
> $msg .= "Another short sentence\n"; // less than 70 characters
> $msg .= "Another very long sentence";
>
> $msg = wordwrap($msg, 70);
>
> Does wordwrap only act on the longer individual strings? Will the short
> strings appear on lines of their own?
>
> In other words, will the formatting (\n) in each string taken separately
> override the overall wordwrap?
>
> Thank you,
>
> Bill B

Did you try it?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: mail function and wordwrap [message #172258 is a reply to message #172256] Tue, 08 February 2011 13:44 Go to previous messageGo to next message
me is currently offline  me
Messages: 192
Registered: September 2010
Karma: 0
Senior Member
On 2/8/2011 8:34 AM, Jerry Stuckle wrote:
> On 2/8/2011 8:19 AM, Bill B wrote:
>> I have looked through php.net (and googled) without finding an example
>> of this particular scenario.
>>
>> If the message is the result of:
>>
>> $msg = "A very long sentence\n";
>> $msg .= "A short sentence\n"; // less than 70 characters
>> $msg .= "Another short sentence\n"; // less than 70 characters
>> $msg .= "Another very long sentence";
>>
>> $msg = wordwrap($msg, 70);
>>
>> Does wordwrap only act on the longer individual strings? Will the short
>> strings appear on lines of their own?
>>
>> In other words, will the formatting (\n) in each string taken separately
>> override the overall wordwrap?
>>
>> Thank you,
>>
>> Bill B
>
> Did you try it?
>

No. Is that the standard?

I am using this in a "listening" script that is triggered by receiving a
notice from PayPal. The PayPal information supplies the variables for
the mail function, including the customer's email address. Based on the
transaction type a different message is composed. There are about 10
different messages of differing content and formatting.

That is difficult to test repeatedly so I turned to this group. If you
think that is misguided, then pass on responding.

Bill B
Re: mail function and wordwrap [message #172259 is a reply to message #172258] Tue, 08 February 2011 14:07 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 2/8/2011 8:44 AM, Bill B wrote:
> On 2/8/2011 8:34 AM, Jerry Stuckle wrote:
>> On 2/8/2011 8:19 AM, Bill B wrote:
>>> I have looked through php.net (and googled) without finding an example
>>> of this particular scenario.
>>>
>>> If the message is the result of:
>>>
>>> $msg = "A very long sentence\n";
>>> $msg .= "A short sentence\n"; // less than 70 characters
>>> $msg .= "Another short sentence\n"; // less than 70 characters
>>> $msg .= "Another very long sentence";
>>>
>>> $msg = wordwrap($msg, 70);
>>>
>>> Does wordwrap only act on the longer individual strings? Will the short
>>> strings appear on lines of their own?
>>>
>>> In other words, will the formatting (\n) in each string taken separately
>>> override the overall wordwrap?
>>>
>>> Thank you,
>>>
>>> Bill B
>>
>> Did you try it?
>>
>
> No. Is that the standard?
>
> I am using this in a "listening" script that is triggered by receiving a
> notice from PayPal. The PayPal information supplies the variables for
> the mail function, including the customer's email address. Based on the
> transaction type a different message is composed. There are about 10
> different messages of differing content and formatting.
>
> That is difficult to test repeatedly so I turned to this group. If you
> think that is misguided, then pass on responding.
>
> Bill B

If you want to know if a function does something specific, the
"standard" is to write a short test script using the function and see if
it works like you think it will.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: mail function and wordwrap [message #172260 is a reply to message #172259] Tue, 08 February 2011 14:12 Go to previous messageGo to next message
me is currently offline  me
Messages: 192
Registered: September 2010
Karma: 0
Senior Member
On 2/8/2011 9:07 AM, Jerry Stuckle wrote:
> On 2/8/2011 8:44 AM, Bill B wrote:
>> On 2/8/2011 8:34 AM, Jerry Stuckle wrote:
>>> On 2/8/2011 8:19 AM, Bill B wrote:
>>>> I have looked through php.net (and googled) without finding an example
>>>> of this particular scenario.
>>>>
>>>> If the message is the result of:
>>>>
>>>> $msg = "A very long sentence\n";
>>>> $msg .= "A short sentence\n"; // less than 70 characters
>>>> $msg .= "Another short sentence\n"; // less than 70 characters
>>>> $msg .= "Another very long sentence";
>>>>
>>>> $msg = wordwrap($msg, 70);
>>>>
>>>> Does wordwrap only act on the longer individual strings? Will the short
>>>> strings appear on lines of their own?
>>>>
>>>> In other words, will the formatting (\n) in each string taken
>>>> separately
>>>> override the overall wordwrap?
>>>>
>>>> Thank you,
>>>>
>>>> Bill B
>>>
>>> Did you try it?
>>>
>>
>> No. Is that the standard?
>>
>> I am using this in a "listening" script that is triggered by receiving a
>> notice from PayPal. The PayPal information supplies the variables for
>> the mail function, including the customer's email address. Based on the
>> transaction type a different message is composed. There are about 10
>> different messages of differing content and formatting.
>>
>> That is difficult to test repeatedly so I turned to this group. If you
>> think that is misguided, then pass on responding.
>>
>> Bill B
>
> If you want to know if a function does something specific, the
> "standard" is to write a short test script using the function and see if
> it works like you think it will.
>

Noted. So I should look to see that everyone who writes to the group for
help provides such evidence, regardless of the complexity of their
problem. Correspondingly, I should fail to see anyone, especially you,
offering suggestions or help in the absence of such evidence. That about
right?

Bill B
Re: mail function and wordwrap [message #172261 is a reply to message #172255] Tue, 08 February 2011 14:51 Go to previous messageGo to next message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
On 08-02-11 14:19, Bill B wrote:
> I have looked through php.net (and googled) without finding an example
> of this particular scenario.
>
> If the message is the result of:
>
> $msg = "A very long sentence\n";
> $msg .= "A short sentence\n"; // less than 70 characters
> $msg .= "Another short sentence\n"; // less than 70 characters
> $msg .= "Another very long sentence";
>
> $msg = wordwrap($msg, 70);
>
> Does wordwrap only act on the longer individual strings? Will the short
> strings appear on lines of their own?

There is, of course, only one string in your example. (which contains
more sentences....)

>
> In other words, will the formatting (\n) in each string taken separately
> override the overall wordwrap?

Yes, the current 'break' character (3rd paramerer) is not changed, so if
a short 'sentence' is found it will be shorter than the specified width
in the second parameter.

>
> Thank you,
>
> Bill B

above concluded after a bit of testing ;)

--
Luuk
Re: mail function and wordwrap [message #172262 is a reply to message #172261] Tue, 08 February 2011 14:54 Go to previous messageGo to next message
me is currently offline  me
Messages: 192
Registered: September 2010
Karma: 0
Senior Member
On 2/8/2011 9:51 AM, Luuk wrote:
> On 08-02-11 14:19, Bill B wrote:
>> I have looked through php.net (and googled) without finding an example
>> of this particular scenario.
>>
>> If the message is the result of:
>>
>> $msg = "A very long sentence\n";
>> $msg .= "A short sentence\n"; // less than 70 characters
>> $msg .= "Another short sentence\n"; // less than 70 characters
>> $msg .= "Another very long sentence";
>>
>> $msg = wordwrap($msg, 70);
>>
>> Does wordwrap only act on the longer individual strings? Will the short
>> strings appear on lines of their own?
>
> There is, of course, only one string in your example. (which contains
> more sentences....)
>
>>
>> In other words, will the formatting (\n) in each string taken separately
>> override the overall wordwrap?
>
> Yes, the current 'break' character (3rd paramerer) is not changed, so if
> a short 'sentence' is found it will be shorter than the specified width
> in the second parameter.
>
>>
>> Thank you,
>>
>> Bill B
>
> above concluded after a bit of testing ;)
>

Thank you, Luuk. Wink noted, message received and appreciated.

Bill B
Re: mail function and wordwrap [message #172267 is a reply to message #172260] Tue, 08 February 2011 19:55 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 2/8/2011 9:12 AM, Bill B wrote:
> On 2/8/2011 9:07 AM, Jerry Stuckle wrote:
>> On 2/8/2011 8:44 AM, Bill B wrote:
>>> On 2/8/2011 8:34 AM, Jerry Stuckle wrote:
>>>> On 2/8/2011 8:19 AM, Bill B wrote:
>>>> > I have looked through php.net (and googled) without finding an example
>>>> > of this particular scenario.
>>>> >
>>>> > If the message is the result of:
>>>> >
>>>> > $msg = "A very long sentence\n";
>>>> > $msg .= "A short sentence\n"; // less than 70 characters
>>>> > $msg .= "Another short sentence\n"; // less than 70 characters
>>>> > $msg .= "Another very long sentence";
>>>> >
>>>> > $msg = wordwrap($msg, 70);
>>>> >
>>>> > Does wordwrap only act on the longer individual strings? Will the
>>>> > short
>>>> > strings appear on lines of their own?
>>>> >
>>>> > In other words, will the formatting (\n) in each string taken
>>>> > separately
>>>> > override the overall wordwrap?
>>>> >
>>>> > Thank you,
>>>> >
>>>> > Bill B
>>>>
>>>> Did you try it?
>>>>
>>>
>>> No. Is that the standard?
>>>
>>> I am using this in a "listening" script that is triggered by receiving a
>>> notice from PayPal. The PayPal information supplies the variables for
>>> the mail function, including the customer's email address. Based on the
>>> transaction type a different message is composed. There are about 10
>>> different messages of differing content and formatting.
>>>
>>> That is difficult to test repeatedly so I turned to this group. If you
>>> think that is misguided, then pass on responding.
>>>
>>> Bill B
>>
>> If you want to know if a function does something specific, the
>> "standard" is to write a short test script using the function and see if
>> it works like you think it will.
>>
>
> Noted. So I should look to see that everyone who writes to the group for
> help provides such evidence, regardless of the complexity of their
> problem. Correspondingly, I should fail to see anyone, especially you,
> offering suggestions or help in the absence of such evidence. That about
> right?
>
> Bill B

No, but which is easier - writing a five line script to test it
yourself, or composing a question, posting it to usenet and waiting a
day or two for a response?

Your question is so easy to test locally it isn't even funny.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: mail function and wordwrap [message #172268 is a reply to message #172261] Tue, 08 February 2011 19:55 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 2/8/2011 9:51 AM, Luuk wrote:
> On 08-02-11 14:19, Bill B wrote:
>> I have looked through php.net (and googled) without finding an example
>> of this particular scenario.
>>
>> If the message is the result of:
>>
>> $msg = "A very long sentence\n";
>> $msg .= "A short sentence\n"; // less than 70 characters
>> $msg .= "Another short sentence\n"; // less than 70 characters
>> $msg .= "Another very long sentence";
>>
>> $msg = wordwrap($msg, 70);
>>
>> Does wordwrap only act on the longer individual strings? Will the short
>> strings appear on lines of their own?
>
> There is, of course, only one string in your example. (which contains
> more sentences....)
>
>>
>> In other words, will the formatting (\n) in each string taken separately
>> override the overall wordwrap?
>
> Yes, the current 'break' character (3rd paramerer) is not changed, so if
> a short 'sentence' is found it will be shorter than the specified width
> in the second parameter.
>
>>
>> Thank you,
>>
>> Bill B
>
> above concluded after a bit of testing ;)
>

IOW you wrote the test script for him, Luuk? How good of you :)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: mail function and wordwrap [message #172269 is a reply to message #172268] Tue, 08 February 2011 21:49 Go to previous messageGo to next message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
On 08-02-11 20:55, Jerry Stuckle wrote:
> On 2/8/2011 9:51 AM, Luuk wrote:
>> On 08-02-11 14:19, Bill B wrote:
>>> I have looked through php.net (and googled) without finding an example
>>> of this particular scenario.
>>>
>>> If the message is the result of:
>>>
>>> $msg = "A very long sentence\n";
>>> $msg .= "A short sentence\n"; // less than 70 characters
>>> $msg .= "Another short sentence\n"; // less than 70 characters
>>> $msg .= "Another very long sentence";
>>>
>>> $msg = wordwrap($msg, 70);
>>>
>>> Does wordwrap only act on the longer individual strings? Will the short
>>> strings appear on lines of their own?
>>
>> There is, of course, only one string in your example. (which contains
>> more sentences....)
>>
>>>
>>> In other words, will the formatting (\n) in each string taken separately
>>> override the overall wordwrap?
>>
>> Yes, the current 'break' character (3rd paramerer) is not changed, so if
>> a short 'sentence' is found it will be shorter than the specified width
>> in the second parameter.
>>
>>>
>>> Thank you,
>>>
>>> Bill B
>>
>> above concluded after a bit of testing ;)
>>
>
> IOW you wrote the test script for him, Luuk? How good of you :)
>

no, i copied the lines in out of the original post....
and added 'echo $msg;' to the end
oh wait, i made the last sentence a bit longer too.... ;)

And, yes, i'm not a consultant, as you are, so i *know* how to do it.

--
Luuk
Re: mail function and wordwrap [message #172270 is a reply to message #172269] Tue, 08 February 2011 21:49 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 2/8/2011 4:49 PM, Luuk wrote:
> On 08-02-11 20:55, Jerry Stuckle wrote:
>> On 2/8/2011 9:51 AM, Luuk wrote:
>>> On 08-02-11 14:19, Bill B wrote:
>>>> I have looked through php.net (and googled) without finding an example
>>>> of this particular scenario.
>>>>
>>>> If the message is the result of:
>>>>
>>>> $msg = "A very long sentence\n";
>>>> $msg .= "A short sentence\n"; // less than 70 characters
>>>> $msg .= "Another short sentence\n"; // less than 70 characters
>>>> $msg .= "Another very long sentence";
>>>>
>>>> $msg = wordwrap($msg, 70);
>>>>
>>>> Does wordwrap only act on the longer individual strings? Will the short
>>>> strings appear on lines of their own?
>>>
>>> There is, of course, only one string in your example. (which contains
>>> more sentences....)
>>>
>>>>
>>>> In other words, will the formatting (\n) in each string taken separately
>>>> override the overall wordwrap?
>>>
>>> Yes, the current 'break' character (3rd paramerer) is not changed, so if
>>> a short 'sentence' is found it will be shorter than the specified width
>>> in the second parameter.
>>>
>>>>
>>>> Thank you,
>>>>
>>>> Bill B
>>>
>>> above concluded after a bit of testing ;)
>>>
>>
>> IOW you wrote the test script for him, Luuk? How good of you :)
>>
>
> no, i copied the lines in out of the original post....
> and added 'echo $msg;' to the end
> oh wait, i made the last sentence a bit longer too.... ;)
>
> And, yes, i'm not a consultant, as you are, so i *know* how to do it.
>

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

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
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: 0
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
  Switch to threaded view of this topic Create a new topic Submit Reply
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 24 11:47:24 GMT 2024

Total time taken to generate the page: 0.02676 seconds