3v4l.org

run code in 500+ PHP versions simultaneously
<?php $html = <<<HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content=""> <meta name="description" content=""> <meta name="author" content=""> <title></title> <link rel="apple-touch-icon" href=""> <link rel="shortcut icon" href=""> <!-- Stylesheets --> <link rel="stylesheet" href=""> <!-- Some Stylesheets --> <link rel="stylesheet" href=""> <!-- Some Stylesheets --> <link rel="stylesheet" href=""> <!-- Some Stylesheets --> <!-- Scripts --> <script src=""></script> </head> <body class=""> <nav class="nav1" role="navigation"> <!-- Some HTML --> </nav> <div class="menubar1"> <!-- Some HTML --> </div> <div class="menubar2"> <div> <div> <ul> <li></li> </ul> </div> </div> <!-- Some HTML --> </div> <!-- ========================================================= --> <!-- ========================================================= --> <!-- PAGE CONTENTS --> <!-- ========================================================= --> <!-- ========================================================= --> <!-- Footer --> <footer class="site-footer"> <!-- Some HTML --> </footer> <script src=""></script> <!-- Some Script Tags --> <script src=""></script> <!-- Some Script Tags --> <script src=""></script> <!-- Some Script Tags --> <script src=""></script> <!-- Some Script Tags --> <!-- Page --> <!-- Google Analytics --> <script> /* Some Scripts */ </script> </body> </html> HTML; libxml_use_internal_errors(true); $doc = new \DOMDocument(); $doc->loadHTML($html); $menubar2_inner_div_count = (new \DOMXPath($doc))->query('//div[@class="menubar2"]//div')->length; $html = preg_replace('/^.*?<div class="menubar2">' . str_repeat('.*?<\/div>', $menubar2_inner_div_count + 1) . '/s', '<!-- Header -->' . PHP_EOL . '<?php include_once "include/header.php" ?>', $html); $html = preg_replace('/<footer class="site-footer">.*?<\/html>/s', '<?php include_once "include/footer.php" ?>', $html); $html = preg_replace('/^ {8}/m', '', $html); echo $html;
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
<!-- Header --> <?php include_once "include/header.php" ?> <!-- ========================================================= --> <!-- ========================================================= --> <!-- PAGE CONTENTS --> <!-- ========================================================= --> <!-- ========================================================= --> <!-- Footer --> <?php include_once "include/footer.php" ?>

preferences:
124.56 ms | 1580 KiB | 4 Q