Skip to content

Instantly share code, notes, and snippets.

@crispy-computing-machine
Created April 17, 2023 11:04
Show Gist options
  • Save crispy-computing-machine/2bd5205dfc3dccf4340e80984557fb1c to your computer and use it in GitHub Desktop.
Save crispy-computing-machine/2bd5205dfc3dccf4340e80984557fb1c to your computer and use it in GitHub Desktop.
PHP self-modifying code
<?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