Re: Formatting output



Patrick wrote:
Jerry Stuckle wrote:
Patrick wrote:

//variable set
$logmonth = $_POST[logmonth];
//and my attempt to format the output
fwrite($out,"%02d\n",$logmonth);
so that it will write to a file
and put a leading 0 in front of single digit months.
Example, for February the output to the file would be 02.
The fwrite doesn't seem to work.
That's because fwrite() doesn't accept a formatting string. You write a string; the third parameter is optional and is the number of bytes to write.
You need fprintf() instead.
fprintf doesn't seem to work for me. It stops things in its tracks and does nothing through the rest of the script beginning at that line.
//I have it as
fprintf($out,"%02d\n",$logmonth);
Is this right?

The syntax is right if $out is a file resource.

--

//Aho
.



Relevant Pages

  • Re: Historical question, why fwrite and not binary specifier for fprintf?
    ... unix write, but no fwrite. ... standard C function fprintf to allow binary operations? ... possible if the format string is not a string literal. ...
    (comp.lang.c)
  • Re: Formatting output
    ... //and my attempt to format the output ... That's because fwritedoesn't accept a formatting string. ... You need fprintf() instead. ... The syntax is right if $out is a file resource. ...
    (alt.php)
  • Re: Formatting output
    ... I am trying to do formatted output of single digit decimals. ... //and my attempt to format the output ... That's because fwritedoesn't accept a formatting string. ... You need fprintf() instead. ...
    (alt.php)
  • Re: Formatting output
    ... I am trying to do formatted output of single digit decimals. ... //and my attempt to format the output ... That's because fwritedoesn't accept a formatting string. ... You need fprintf() instead. ...
    (alt.php)
  • Re: Formatting output
    ... I am trying to do formatted output of single digit decimals. ... //and my attempt to format the output ... That's because fwrite() doesn't accept a formatting string. ...
    (alt.php)