hello, how can I get fwrite to stop casting everything to strings when it writes.
for example
$number = 33; $fp = fopen ("file", "w"); fputs($fp,$number,4);
will give me a 'file' with "33 " although something like " !" is to be expected.
excuse my ignorance, why is " !" expected?
in ascii decimal '33' = ! i am not sure if this is what it would output with php, but I know that it shouldnt be outputting '33'
this may be overkilll... but have you tried serializing... converts any php object/variable into an ascii string...
read more here: http://www.php.net/manual/en/function.serialize.php http://www.php.net/manual/en/function.unserialize.php
s'cos PHP seems to do implicit conversion and in this case 33 = "33". AFAIK PHP does not do the c type thing of ascii characters being equal to numeric values...
if you really want to dump ascii characters out which have been converted from numbers then go use the chr() function.
anyone else got any ideas?
What else are you looking for? As far as I can see, the above answers seem to answer your question.
perhaps I am insane (the answer I am looking for is not an option) but I am looking for a way to write to a file without everything being cast to type string.
pardon me for being difficult, but im not sure you want to do that. If you are only going to use php there is no reason to use anything but a string, as php (in a sense) thinks in strings.
Are you having php write a file so another language can read it?
maybe describing your situation more will help us point you in the right direction.
perhaps you should look into functions like pack:
http://www.php.net/manual/en/function.pack.php
or read up on php's type juggling, you can manually settype() a variable:
http://www.php.net/manual/en/function.settype.php http://www.php.net/manual/en/language.types.type-juggling.php