开发者

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


You can write the character code directly to the file:

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


PHP does not treat single characters as a special type. Buts, as PHP string is just an sequence of octects, there is no problem in writing this:

  fwrite(fp,"\x10");


You would have to open a file in binary mode and then use

  • use the function pack to pack the int in the type of int you want
  • then use the function fwrite on the value you packed
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜