Skip to content

Instantly share code, notes, and snippets.

@dshafik
Created September 27, 2013 03:29
Show Gist options
  • Select an option

  • Save dshafik/6723774 to your computer and use it in GitHub Desktop.

Select an option

Save dshafik/6723774 to your computer and use it in GitHub Desktop.

Revisions

  1. dshafik created this gist Sep 27, 2013.
    19 changes: 19 additions & 0 deletions tokenize.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    #!/usr/bin/env php
    <?php
    if (!isset($_SERVER['argv'][1])) {
    echo "Usage: {$_SERVER['argv'][0]} <filename>" . PHP_EOL;
    exit;
    }

    $tokens = token_get_all(file_get_contents($_SERVER['argv'][1]));
    foreach ($tokens as $token) {
    if (is_integer($token[0])) {
    echo str_pad(token_name($token[0]), 28);
    echo trim($token[1]);
    } else {
    echo str_repeat(" ", 28);
    echo $token[0];
    }
    echo PHP_EOL;
    }
    ?>