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

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

<p>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.</p>

<p>Thanks for your time.</p>

[{'answer_id': 77585, 'author': 'nsayer', 'author_id': 13757, 'author_profile': 'https://Stackoverflow.com/users/13757', 'pm_score': 4, 'selected': True, 'text': '<p><code>fwrite()</code> takes strings. Try <code>chr(0x63)</code> if you want to write a <code>0x63</code> byte to the file.</p>\n'}, {'answer_id': 77597, 'author': 'Don Neufeld', 'author_id': 13097, 'author_profile': 'https://Stackoverflow.com/users/13097', 'pm_score': 1, 'selected': False, 'text': '<p>You are trying to pass an int to a function that accepts a string, so it\'s being converted to a string for you.</p>\n\n<p>This will write what you want:</p>\n\n<pre><code>fwrite($fpr, "\\x63");\n</code></pre>\n'}, {'answer_id': 77626, 'author': 'Paige Ruten', 'author_id': 813, 'author_profile': 'https://Stackoverflow.com/users/813', 'pm_score': 2, 'selected': False, 'text': "<p>That's because fwrite() expects a string as its second argument. Try doing this instead:</p>\n\n<pre><code>fwrite($fpr, chr(0x63));\n</code></pre>\n\n<p>chr(0x63) returns a string with one character with ASCII value 0x63. (So it'll write the number 0x63 to the file.)</p>\n"}, {'answer_id': 8965004, 'author': 'Christian', 'author_id': 314056, 'author_profile': 'https://Stackoverflow.com/users/314056', 'pm_score': 0, 'selected': False, 'text': '<p>If you really want to write binary to files, I would advise to use the <code>pack()</code> approach together with the file API.</p>\n\n<p><a href="https://stackoverflow.com/questions/5719803/what-is-the-realtime-use-of-php-pack-and-unpack-function">See this question</a> for an example.</p>\n'}]
['https://Stackoverflow.com/questions/77558', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10333/']