3v4l.org

run code in 300+ PHP versions simultaneously
<?php class mnem { public function crawlAndSwap($sourceDir, $destinationDir) { // Create recursive iterators to traverse the directory tree $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($sourceDir, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $file) { echo $file."<br>\r\n"; if ($file->isFile() && $file->getExtension() === 'php') { $filePath = $file->getPathname(); // Read the contents of the PHP file $contents = file_get_contents($filePath); // Perform your content swapping here // Example: Replace "old content" with "new content" // $newContents = str_replace("old content", "new content", $contents); $newContents = $this->bufferSwap($contents); // Determine the destination path for the modified file $destinationPath = str_replace($sourceDir, $destinationDir, $filePath); // Ensure the destination directory exists $destinationFileDir = dirname($destinationPath); if (!is_dir($destinationFileDir)) { mkdir($destinationFileDir, 0777, true); } // Write the modified contents to the destination file file_put_contents($destinationPath, $newContents); } } } public function crawlSwap() { // Example usage $sourceDir = $_SERVER["DOCUMENT_ROOT"]."/"; $destinationDir = realpath($_SERVER["DOCUMENT_ROOT"]."/../reversion/"); if(!is_dir($destinationDir)) {mkdir($destinationDir,0777,true);} $this->crawlAndSwap($sourceDir, $destinationDir); } }
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7

preferences:
45.77 ms | 402 KiB | 62 Q