3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $lien = "http://www.hatshowroom.com/chapeaux/8-feutre-monkey-noir-3000008353259.html"; if(urlExist($lien) === FALSE){ echo 'KO'; } else { echo "Good"; } function urlExist($url) { $url = @parse_url($url); if (!$url) return false; $url = array_map('trim', $url); $url['port'] = (!isset($url['port'])) ? 80 : (int)$url['port']; $path = (isset($url['path'])) ? $url['path'] : '/'; $path .= (isset($url['query'])) ? "?$url[query]" : ''; if (isset($url['host']) && $url['host'] != gethostbyname($url['host'])) { $fp = fsockopen($url['host'], $url['port'], $errno, $errstr, 30); if (!$fp) return false; //socket not opened fputs($fp, "HEAD $path HTTP/1.1rnHost: $url[host]rnrn"); //socket opened $headers = fread($fp, 4096); fclose($fp); if(preg_match('#^HTTP/.*s+[(200|301|302)]+s#i', $headers)){//matching header return true; } else return false; } // if parse url else return false; }
based on 8MQ9E
Output for 4.3.0 - 7.2.0
KO