Re: Formatting output



Patrick wrote:
Hi All,

Using Version 4.3.9 (Stuck with it for now).

Anyhow, I am trying to do formatted output of single digit decimals. I have a form and present you an abbreviated example for getting a month value.

<select class="inform" name="logmonth">
<option value="1">Jan</option>
<option value="2">Feb</option>
<option value="3">Mar</option>
</select>

and upon submit it runs through another php process

//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.

Any suggestions would be appreciated.

Thanks


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.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================

.



Relevant Pages

  • 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 ... You write a string; the third parameter is optional and is the number of bytes to write. ... You need fprintf() instead. ...
    (alt.php)
  • Re: Requiring a date be entered as mm/dd/yy on a form field.
    ... completely validate a date entered in this format. ... cultures often have difficulty even comprehending internationalizaion ... can easily be done and will cause some input errors to be corrected: ... For a common case of a single digit being off by one, ...
    (microsoft.public.scripting.jscript)
  • Re: Formatting output
    ... //and my attempt to format the output ... That's because fwrite() doesn't accept a formatting string. ... You need fprintf() instead. ...
    (alt.php)