3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Disable time limit to keep the script running set_time_limit(0); // Domain to start crawling $domain = "http://webdevwonders.com"; // Content to search for existence $content = "google-analytics.com/ga.js"; // Tag in which you look for the content $content_tag = "script"; // Name of the output file $output_file = "analytics_domains.txt"; // Maximum urls to check $max_urls_to_check = 100; $rounds = 0; // Array to hold all domains to check $domain_stack = array(); // Maximum size of domain stack $max_size_domain_stack = 1000; // Hash to hold all domains already checked $checked_domains = array(); // Loop through the domains as long as domains are available in the stack // and the maximum number of urls to check is not reached while ($domain != "" && $rounds < $max_urls_to_check) { $doc = new DOMDocument(); // Get the sourcecode of the domain @$doc->loadHTMLFile($domain); $found = false; // Loop through each found tag of the specified type in the dom // and search for the specified content foreach($doc->getElementsByTagName($content_tag) as $tag) { if (strpos($tag->nodeValue, $content)) { $found = true; break; } } // Add the domain to the checked domains hash $checked_domains[$domain] = $found; // Loop through each "a"-tag in the dom // and add its href domain to the domain stack if it is not an internal link foreach($doc->getElementsByTagName('a') as $link) { $href = $link->getAttribute('href'); if (strpos($href, 'http://') !== false && strpos($href, $domain) === false) { $href_array = explode("/", $href); // Keep the domain stack to the predefined max of domains // and only push domains to the stack that have not been checked yet if (count($domain_stack) < $max_size_domain_stack && $checked_domains["http://".$href_array[2]] === null) { array_push($domain_stack, "http://".$href_array[2]); } }; } } $found_domains = ""; // Add all domains where the specified search string // has been found to the found domains string foreach ($checked_domains as $key => $value) { if ($value) { $found_domains .= $key."\n"; } } echo $found_domains;
Output for 5.1.5 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.28, 5.4.0 - 5.4.24, 7.2.29 - 7.2.33, 7.3.16 - 7.3.33, 7.4.3 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6

Process exited with code 137.

preferences:
180.01 ms | 404 KiB | 214 Q