Search code examples
phpcfopenfwrite

php equivalent to C's fputc


I am wondering if there is an equivalent to C's fputc in PHP? I am trying to do the following C code in PHP:

fputc(0x10, fp);

more information on fputc: http://en.wikipedia.org/wiki/C_file_input/output#Writing_to_a_stream_using_fputc

Thanks


Solution

  • You can write the character code directly to the file:

    fputs($fp, "\x10");
    // or
    fputs($fp, chr(16)); 
    // or
    fputs($fp, chr(hexdec(10));