views:

58

answers:

3

File 1:

asdffdsa

File 2:

asdfjklfdsaHGUik

How do I read these binary files with PHP such that I can populate an array with the plaintext like:

$file1_output = ["asdf", "fdsa"];
$file2_output = ["asdfjkl", "fdsaHGUik"];
A: 

Not sure if you could do this some better way, but maybe reading char-by-char from file and checking if it's ASCII code (using ord() function) is in range you're interested in - would also do the trick?

Laimoncijus
A: 

This will match any word character (0-9,a-z,A-Z and _):

preg_match_all(
    "/[\x30-\x39\x5F\x41-\x5A\x61-\x7a]+/", /* regexp */
    file_get_contents('file1'),             /* file contents */
    $file1_output                           /* array to populate */
);
dev-null-dweller
A: 

To build on what @Frank Farmer said, I'd use strings:

<?php

$strings_command = '/usr/bin/strings';

$file1_output = array();
$file2_output = array();

exec("$strings_command $path_to_file1",$file1_output);
exec("$strings_command $path_to_file2",$file2_output);

?>
Josh
Thanks for the answers. I ended up just spending 5 or 6 hours and cracked the format of the binary.strings is a very useful program I had not known about, though.
Chris G.