Created
April 17, 2023 11:04
-
-
Save crispy-computing-machine/2bd5205dfc3dccf4340e80984557fb1c to your computer and use it in GitHub Desktop.
PHP self-modifying code
This file contains 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 characters
<?php | |
// Define the code to modify | |
$code = <<<EOT | |
<?php | |
echo "Hello, world!"; | |
?> | |
EOT; | |
// Modify the code | |
$code = str_replace('world', 'PHP', $code); | |
// Save the modified code to a file | |
$file = fopen(__FILE__, 'w'); | |
fwrite($file, $code); | |
fclose($file); | |
// Execute the modified code | |
include __FILE__; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment