ddawsonNOSPAM at execpc dot com
10-May-2000 07:59
[Editor's note:
%c is defined as: "Print the character
belonging to the ascii code given"
chr() just gives a string,
so you need to use %s, even if the string consists of only one character.
This is consistent with other
languages.
--Jeroen@php.net]
Learn from my
mistake:
Do not expect this to work!
<?php
$c_question
= chr(63);
$v_out = sprintf("<%cphp\n",
$c_question);
//... more stuff being sprintf'd into v_out here
...
$v_out = sprintf("%s%c>\n", $v_out,
$c_question);
$v_fp = fopen("foofile", "w");
if
($v_fp)
{
fwrite($v_fp, $v_out, strlen($v_out));
fclose($v_fp);
}
?>
When I did this, foofile contained
<NUL NUL NUL NUL NUL>.
I spun my wheels quite awhile looking at
fputs, fwrite to verify I was calling those functions correctly.
My
mistake was using $c_question = chr(63) instead of
$c_question = 63
(correct). Then everything worked fine.