Page 1 of 1

Text file to .Dat file Conversion in PHP

Posted: Mon Nov 23, 2009 7:52 am
by jebaraj
Hi All,
Could anybody provide code for Text file to .Dat file Conversion in PHP. :banghead:

Thanks,
Jeba Raj.

Re: Text file to .Dat file Conversion in PHP

Posted: Mon Nov 23, 2009 8:21 am
by AbraCadaver

Code: Select all

copy('filename.txt', 'filename.dat');

Re: Text file to .Dat file Conversion in PHP

Posted: Mon Nov 23, 2009 8:39 am
by jebaraj
If we use "copy('filename.txt', 'filename.dat');" both .txt and .dat files have same content. But i need .dat should be in binary coded format.

Re: Text file to .Dat file Conversion in PHP

Posted: Mon Nov 23, 2009 8:56 am
by AbraCadaver
jebaraj wrote:If we use "copy('filename.txt', 'filename.dat');" both .txt and .dat files have same content. But i need .dat should be in binary coded format.
Yes, that was an important bit of information wasn't it? Try and assume that no one has any idea what your .dat file is or what the format is. :idea:

Code: Select all

$txt = file_get_contents('filename.txt');
 
$bin = "";
for($i=0; $i < strlen($txt); $i++ ){
    $bin .= sprintf("%08s ", decbin(ord($txt[$i])));
}
 
file_put_contents('filename.dat', $bin);
-Shawn

Re: Text file to .Dat file Conversion in PHP

Posted: Tue Nov 24, 2009 4:13 am
by jebaraj
Hi,
Thanks for quick reply. if i use decbin() it will convert to 0's and 1's. But i need .dat file format as "http://www.cooketech.co.uk/convertor/Te ... 20FORM.dat".

Can any one help me, what format of file is this .dat file(Binary or ASCII or...)?

I need text files to be converted like above .dat format!

Thanks,
Jeba Raj

Re: Text file to .Dat file Conversion in PHP

Posted: Tue Nov 24, 2009 9:46 am
by AbraCadaver
jebaraj wrote:Hi,
Thanks for quick reply. if i use decbin() it will convert to 0's and 1's. But i need .dat file format as "http://www.cooketech.co.uk/convertor/Te ... 20FORM.dat".

Can any one help me, what format of file is this .dat file(Binary or ASCII or...)?

I need text files to be converted like above .dat format!

Thanks,
Jeba Raj

Ah ha! Now we are getting some details. One at a time, but we have some. Do you happen to know what application creates the .dat file or if there is a specification for the .dat file somewhere? If I were to ask you how to convert a .txt file to a .bob file, what would you say?

-Shawn

Re: Text file to .Dat file Conversion in PHP

Posted: Tue Nov 24, 2009 11:04 pm
by jebaraj
Hi,

Thank for u r reply.Sony camera creates this .dat file!

Thanks,
Jeba Raj