Forum Moderators: coopster

Message Too Old, No Replies

wordwrap() woes

         

neophyte

11:37 pm on Jun 4, 2012 (gmt 0)

10+ Year Member



Hello All -

Got a problem with wordwrap() when using it to wrap text with spaces between words for output in a plain text email.

Testing email client is outlook 2010.

I'm calling the function like so:

$bodyText = wordwrap($temp['Text'], 70, "\n", FALSE);

Now, if I put in a long long string of characters WITHOUT SPACES, the function wraps everything nicely to 70 chars as expected.

BUT, if it's a paragraph of regular text including spaces, it doesn't wrap the line at all.

I've seen some discussion regarding utf-8 strings and have tried some of those function alternatives but, unfortunately, with the exact same result as php's own wordwrap function.

So, I'm at a loss - can anyone let me know what's going on and how I can fix this?

incrediBILL

9:52 am on Jun 5, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



First thing I would try is changing your fourth parameter 'cut' to TRUE and see if that changes anything.

If it doesn't, provide a sample of working and non-working code including the text being used.

neophyte

11:07 am on Jun 5, 2012 (gmt 0)

10+ Year Member



Hello Bill -

Thanks for your reply.

Tried setting cut to TRUE - same result.

Interesting though... I tried to just echo two strings (one with and one without spaces) using BR as the brake character (cut = TRUE) and it worked perfectly on both strings.

See test code below.

So, this had got me thinking that this is an email client thing, so I tried using "\r\n" (rather than simply "\n") but I got the same result: string with spaces didn't break; string with no spaces broke as expected.

I'm not processing the text in any way before I'm email it which has really got me stumped.

Anybody got any ideas?

++++++++++++++++++++++++++++++

Test Code - Screen Display

++++++++++++++++++++++++++++++

$textSpace = 'Morbi ligula risus, accumsan sit amet, interdum hendrerit, pellentesque in, erat. Sed condimentum, justo ut consequat tincidunt, mauris felis pulvinar lectus, non dignissim eros mauris ac velit.';

$textNoSpace = 'Morbiligularisus,accumsansitamet,interdumhendrerit,pellentesquein,erat.Sedcondimentum,justoutconsequattincidunt,maurisfelispulvinarlectus,nondignissimerosmaurisacvelit.';

$text1 = wordwrap($textSpace, 70, "<br>", TRUE);

$text2 = wordwrap($textNoSpace, 70, "<br>", TRUE);

echo $text1 , '<br><br>' , $text2;

coopster

2:05 pm on Jun 12, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



So it's not likely the word wrapping that is the issue but the way you are sending the email? Are you certain it is being sent and arriving as plain text email?

neophyte

10:07 am on Jun 13, 2012 (gmt 0)

10+ Year Member



Hi Coopster - and others.

I was tinkering around this again this morning and then noticed that little "warning" line in the Outlook header of the resulting text email: "extra line breaks were removed".

Oh man!

Clicked the "restore line breaks option" and all is well with everything.

Why in the world would Outlook tinker with plain-text line breaks in the first place?

Oh well... sorry to everyone for this bother.

Neophyte