3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function get_domain($url, $with_www = false) { $url = preg_replace('#^https?://#', '', trim($url)); $path = explode('/', $url); $domain = strtolower(trim($path[0])); $domain = preg_replace('#^www.#', '', $domain); if($with_www) { $domain = 'www.' . $domain; } return $domain; } function format_url($url) { if(parse_url($url, PHP_URL_SCHEME) === null) { $url = 'http://' . $url; //parse_url() requires scheme to parse URL correctly } $parsed_url = parse_url($url); $formatted_url = get_domain($parsed_url['host'], false); if (isset($parsed_url['path'])) { $formatted_url .= $parsed_url['path']; } if (isset($parsed_url['query'])) { $formatted_url .= '?' . $parsed_url['query']; } $formatted_url = rtrim($formatted_url, '/'); return $formatted_url; } $url = 'http://www.igrushka-spb.ru/index.php?categoryID=1718'; var_dump(format_url($url));
Output for 5.1.2 - 7.1.0
string(41) "igrushka-spb.ru/index.php?categoryID=1718"
Output for 4.3.4 - 5.1.1
Notice: Use of undefined constant PHP_URL_SCHEME - assumed 'PHP_URL_SCHEME' in /in/aLXnQ on line 19 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/aLXnQ on line 19 string(51) "http//www.igrushka-spb.ru/index.php?categoryID=1718"
Output for 4.3.2 - 4.3.3
Notice: Use of undefined constant PHP_URL_SCHEME - assumed 'PHP_URL_SCHEME' in /in/aLXnQ on line 19 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/aLXnQ on line 19 Warning: parse_url(http://http://www.igrushka-spb.ru/index.php?categoryID=1718): Unable to parse url in /in/aLXnQ on line 23 string(0) ""
Output for 4.3.0 - 4.3.1
Notice: Use of undefined constant PHP_URL_SCHEME - assumed 'PHP_URL_SCHEME' in /in/aLXnQ on line 19 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/aLXnQ on line 19 Warning: parse_url(http://http://www.igrushka-spb.ru/index.php?categoryID=1718) [http://www.php.net/function.parse-url]: Unable to parse url in /in/aLXnQ on line 23 string(0) ""