Skip to content

Instantly share code, notes, and snippets.

@sgolemon

sgolemon/octalizer.php Secret

Created Oct 21, 2020
Embed
What would you like to do?
Octalizer
<?php declare(strict_types=1);
// Usage: octalize.php [infile.php [outfile.php]]
$tokens = PhpToken::getAll(file_get_contents($_SERVER['argv'][1] ?? 'php://stdin'));
$out = fopen($_SERVER['argv'][2] ?? $_SERVER['argv'][1] ?? 'php://stdout', 'wt');
foreach($tokens as $token) {
if (($token->id === T_LNUMBER) && (strlen($token->text) > 2) && ($token->text[0] === '0') && is_numeric($token->text[1])) {
fwrite($out, '0o' . substr($token->text, 1));
} else {
fwrite($out, $token->text);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment