Skip to content

Instantly share code, notes, and snippets.

@ryanve
Created March 18, 2013 20:42
Show Gist options
  • Save ryanve/5190628 to your computer and use it in GitHub Desktop.
Save ryanve/5190628 to your computer and use it in GitHub Desktop.
Show source of a PHP file its .txt extension if it exists.
<?php
# Show source of this file in .txt extension if it exists
call_user_func(function() {
$txt = __FILE__ . '.txt';
if ( ! file_exists($txt))
return;
# update (cache at least 5-min)
if (300 < time() - filemtime($txt))
file_put_contents($txt, file_get_contents(__FILE__));
# message
$txt = basename($txt);
echo "/* PHP source: $txt */\n";
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment