3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Return domain name from url * For example: "all.ru" from "http://www.all.ru/test/test.html" * * @param $url * @param bool $with_www * @return string : domain name */ 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; } /** * Format URL * * @param $url * @return string */ function format_url($url) { $parsed_url = parse_url($url); var_dump($parsed_url); $host = get_domain($parsed_url['host'], false); $path = preg_replace('#index\.[a-z]+#', '', $parsed_url['path']); $url = $host . $path; if (isset($parsed_url['query'])) { $url .= '?' . $parsed_url['query']; } return rtrim($url, '/'); } /** * Compare two formatted urls * * @param string $url_1 * @param string $url_2 * @return bool */ function compare_urls($url_1, $url_2) { return format_url($url_1) === format_url($url_2); } $url_1 = 'http://seos.bolseo.ru/index.php?module=2&siteID=235'; $url_2 = 'seos.bolseo.ru/?module=2&siteID=235'; var_dump(compare_urls($url_1, $url_2));
Output for git.master, git.master_jit, rfc.property-hooks
array(4) { ["scheme"]=> string(4) "http" ["host"]=> string(14) "seos.bolseo.ru" ["path"]=> string(10) "/index.php" ["query"]=> string(19) "module=2&siteID=235" } array(2) { ["path"]=> string(15) "seos.bolseo.ru/" ["query"]=> string(19) "module=2&siteID=235" } Warning: Undefined array key "host" in /in/rbYIc on line 37 Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /in/rbYIc on line 13 bool(true)

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:
44.29 ms | 402 KiB | 8 Q