Skip to content

Instantly share code, notes, and snippets.

@gooh
Last active December 18, 2015 22:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gooh/5856488 to your computer and use it in GitHub Desktop.
Save gooh/5856488 to your computer and use it in GitHub Desktop.
A simple linter for code snippets. Writes the snippet to a temp file and then captures and returns the output of php's commandline lint
<?php
function lint($code)
{
$code = strpos($code, '<?php') === 0 ? $code : "<?php $code";
$filename = tempnam(sys_get_temp_dir(), 'lnt');
file_put_contents($filename, $code);
exec(PHP_BINARY . " -l $filename", $errors);
unlink($filename);
return $errors;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment