I'm an experienced programmer but relative beginner to PHP and am
struggling to write binary data to a file in PHP - I've looked at the
Coggeshall guide but I'm still struggling.
Could someone please write a PHP function called WriteToBinary here
where for instance I would pass it the hexadecimal values only in s
string as follows
$output_file == 'C:temp.txt';
$input_string == '5A0010D3A8C6000000D9C5E2D6E4D9C3C5';
WriteToBinary($input_string,$output_file);
Where each set of two characters is one byte in the binary file
This function would write this record to a binary file (you can assume
it will be CRLF delimited records but preferably I'd like to be able
to amend this so assign this delimiter as an amendable constant)
Equally if this isn't possible in PHP then let me know.
The answer would need to be heavily commented and self documenting so
that an idiot like myself can understand it.
Thanks very much in advance.
Thank you very very much for the comments - most helpful - I'll look into these.
However I may be wasn't clear that my answer needs to be a class /
function which I can call with my string.
I'll tip heavily for a good answer - I prefer to do it this way in
case I get an answer which isn't really suitable.
Check out this: http://us4.php.net/manual/en/function.fwrite.php
There are nice comments how to send binaries to files or MySQL.
I never get this right.
$somecontent = $arg1; should be
$somecontent = $arg_1;
Sorry about that.
crythias-ga,
Thank you very much for your comments - I knew how to write files
before, I just wanted to write the binary.
I had got this far already with the comments about the pack() command
which I didn't know already done - but it's not quite there and sicne
you're not a GA researcher you can't place this as an answer
apparently.
It would need to create the file first time through - so the
is_writable check is no good - and I didn't want the echo's - I just
wanted to create the file write the first record and then append as I
went along in the script.
I can now work it out now though - so as requested I'll cancel this question. Advanced Rss To Html Script Released:: Oct 10, 2006 A new add on php script, rss2html pro not only dynamically converts rss and because the resulting page is pure HTML, it will be in a format the RSS feeds in realtime, so no periodic maintenance is required. Lady Sybilla Apologizes to Stephenie Meyer for Writing Russet Noon - 1645 views http://www.prlog.org/10002207-advanced-rss-to-html-script-released.htmlHOME | OPSAT.Net - bob's Blog - Developing PHP-GTK Applications on Linux:: May 20, 2007 In KateOS all the required files exist inside the main binary packages, we define the application 'binary' as the primary script that launches Pure PHP libraries may ''not'' be placed in /usr/lib because the GNU http://www.opsat.net/user/bob/kateos-phpgtk-devHOME |
ok, I guess this is still needing to be answered, or else you would
have cancelled this, or you're ignoring it...
From this page http://www.php.net/manual/en/language.functions.php we
copy the example, change the word foo to the word WriteToBinary.
Reduce the argument list to two arguments, clear the echo and return
lines and paste the example from the above link inside the function,
trimming the second example of .
Thus, the combined function and binary write is:
This very much will be the answer you requested, exactly. I am not a
Google Answers Researcher. If you feel this has answered your
question, please cancel/expire it. If you need clarification, go ahead
and ask, but the documentation for either "function" or "write" has
been very nicely detailed at the given links. The content is copied
under the terms of the : 1997 - 2004 by the PHP
Documentation Group. This material may be distributed only subject to
the terms and conditions set forth in the Open Publication License,
v1.0 or later (the latest version is presently available at
http://www.opencontent.org/openpub/).
http://www.php.net/manual/en/.php
OK, Shall we try one last time?
Using examples in comments at
http://www.php.net/manual/en/function.bin2hex.php and
http://us2.php.net/manual/en/function.pack.php and above code:
Where's The Advantage In Windows Genuine Advantage?
Stocks Bounce After S&P Joins Bear Market
|