Created
April 21, 2012 02:08
-
-
Save cgardner/2433264 to your computer and use it in GitHub Desktop.
Revisions
-
Craig Gardner created this gist
Apr 21, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ <?php $var = <<<VAR 1 VAR; // do stuff here echo $var; register_shutdown_function(function() { $contents = file_get_contents(__FILE__); $pattern = "\$var = <<<VAR\n%s\nVAR;"; $search_pattern = '@\\'. sprintf($pattern, '(.*)') .'@m'; preg_match($search_pattern, $contents, $matches); $new_contents = preg_replace_callback($search_pattern, function($matches) { return str_replace($matches[1], $matches[1] + 1, $matches[0]); }, $contents); file_put_contents(__FILE__, $new_contents, LOCK_EX); });