3v4l.org

run code in 300+ PHP versions simultaneously
<?php $testArray = array( 'sub1.sub2.example.co.uk', 'sub1.example.com', 'example.com', 'sub1.sub2.sub3.example.co.uk', 'sub1.sub2.sub3.example.com', 'sub1.sub2.example.com' ); foreach($testArray as $k => $v) { echo $k." => ".extract_domain($v)."\n"; } function extract_domain($domain) { if(preg_match("/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i", $domain, $matches)) { return $matches['domain']; } else { return $domain; } } function extract_subdomains($domain) { $subdomains = $domain; $domain = extract_domain($subdomains); $subdomains = rtrim(strstr($subdomains, $domain, true), '.'); return $subdomains; }
Output for git.master, git.master_jit, rfc.property-hooks
0 => example.co.uk 1 => example.com 2 => example.com 3 => example.co.uk 4 => example.com 5 => example.com

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:
39.39 ms | 401 KiB | 8 Q