Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use the PHP File api to write raw bytes?

Tags:

php

file-io

I want to write a raw byte/byte stream to a position in a file. This is what I have currently:

$fpr = fopen($out, 'r+');
fseek($fpr, 1); //seek to second byte
fwrite($fpr, 0x63); 
fclose($fpr);

This currently writes the actually string value of "99" starting at byte offset 1. IE, it writes bytes "9" and "9". I just want to write the actual one byte value 0x63 which happens to represent number 99.

Thanks for your time.

like image 806
JP Richardson Avatar asked Oct 21 '25 15:10

JP Richardson


1 Answers

fwrite() takes strings. Try chr(0x63) if you want to write a 0x63 byte to the file.

like image 69
nsayer Avatar answered Oct 23 '25 04:10

nsayer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!