27 lines
444 B
PHP
27 lines
444 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
$path = $argv[1] ?? null;
|
|
if (!$path) {
|
|
fwrite(STDERR, "Usage: php scripts/inspect_encoding.php <file>\n");
|
|
exit(2);
|
|
}
|
|
|
|
$fp = fopen($path, 'rb');
|
|
if (!$fp) {
|
|
fwrite(STDERR, "Cannot open: $path\n");
|
|
exit(1);
|
|
}
|
|
|
|
$bytes = fread($fp, 16);
|
|
fclose($fp);
|
|
|
|
$arr = [];
|
|
for ($i = 0; $i < strlen($bytes); $i++) {
|
|
$arr[] = ord($bytes[$i]);
|
|
}
|
|
|
|
fwrite(STDOUT, json_encode($arr));
|
|
fwrite(STDOUT, PHP_EOL);
|
|
|