Forum Moderators: coopster
I'm almost done my php shopping cart but the only problem I have I have is with the plain text email.
As you will see I am using sprintf to try and format the invoice but no matter what I try, the columns are never lined up. I know there is a way to do this, but I can't see how and this is my last resort for help :).
$confirmation .= sprintf("%08s %40s %5s %4s %8s\n", $item, $productname,$productprice, $productquantity, $totalproductprice);
I'm not sure if this will show up right, but the items below appear on a single line. If you took each line, you would see they are far from being aligned.
11158250 Rainwater Shampoo $6.85 1 $6.85
11544100 Scalp Lotion (Itchy flaking scalp) $30.75 7 $215.25
00022113 25 ml. Cobalt Round / Dropper - 1 oz. $1.60 2 $3.20
I would be so thankful if anyone can show me how to format text into columns of equal width (virtually) using sprintf or any other php function.
Thanks guys.
Cheers
:)
Try
$confirmation .= sprintf("%08s %'-40s %'-5s %'-4s %'-8s\n", $item, $productname,$productprice, $productquantity, $totalproductprice);
and see what it does. (I haven't checked the code!)
(comment: haven't seen netizens answer here, but this is still valuable i think)
from what i know so far about sprintf, your code looks ok. parameters are right (
%[i]#n[/i]s), i'm just wondering if the output is pre-formatted (i.e. a font like courier used and duplicate spaces are displayed. use the
<pre></pre> tag in your html output to verify or use an emailclient which uses courier new as font to display mails. --hakre
you can configure outlook express to use courier on plain text mails. i did ever because a lot of mails using plain text look better and are formated better with a fixed-width font like courier.
anyways now with eudora, every plain text mail is displayed in courier by default. hope that helps you a bit for your decisions.
--hakre