3v4l.org

run code in 300+ PHP versions simultaneously
<?php function findWord(String $html, String $searchWord): Bool { $dom = new DOMDocument; libxml_use_internal_errors(true); $dom->loadHTML($html); $htmlContent = $dom->getElementsByTagName('body')->item(0); $text = $htmlContent->textContent; return strpos($text, $searchWord) !== false; } // First let's start with html we know the word exists $html = <<<'HTML' <html> <head> <meta content="illustrative productions"> <script> var illustrative = true; </script> <style> .illustrative { background-color: #fff; } </style> </head> <body> <h1 class="illustrative">Hello World</h1> <p>Your search word appears here. <strong>illustrative</strong></p> </body> </html> HTML; // Gives us "Found" if (findWord($html, "illustrative")) { echo "Found"; } else { echo "Not Found"; } // Now let's try HTML we know the word doesn't exist $html = <<<'HTML' <html> <head> <meta content="illustrative productions"> <script> var illustrative = true; </script> <style> .illustrative { background-color: #fff; } </style> </head> <body> <h1 class="illustrative">Hello World</h1> <p>Your search word never appears here.</p> </body> </html> HTML; // Gives us "Not Found" if (findWord($html, "illustrative")) { echo "Found"; } else { echo "Not Found"; }
Output for git.master, git.master_jit, rfc.property-hooks
FoundNot Found

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
27.46 ms | 405 KiB | 5 Q