Replace one last byte in file using PHP

i want to run php from shell to REPLACE ONE LAST byte in file (`test` in example) with another byte (`A` in example):
php -r '$fp = fopen("test","r+"); fseek($fp,-1,SEEK_END); fwrite($fp,"A"); fclose($fp);'
but, it wont replace - just adding one byte to the end…
any ideas?

if you fwrite to it maybe r+ is not the best flag
i only replace one last byte
it can be done proper way?
how i can use non ascii (whew i write "A")
0×255 ?
where*
what are you trying to write there?
i want to replace last byte in binary file
it can be 0-127
php.net/ord
k
php.net/chr
the latter
no
i dont need to convert letters
fwrite($fp, chr(0));
for example
ok!  Thanks!

*
To prove that you're not a bot, enter this code
Anti-Spam Image

Leave a Comment

You must be logged in to post a comment.


Blog Tags:

Similar posts: