3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function test($check) { $rx = '_^(https?)://([^:/?]+)(?::(\d+))?(?:(/[^?]+))?(?:\?(.*))?$_i'; echo "Test $check\n"; if (!preg_match($rx, $check, $m)) { echo "\tFAIL!\n"; } else { var_export($m); echo "\n"; } } test(''); test('http://www.example.com'); test('http://www.example.com:8080'); test('http://www.example.com/some/path'); test('http://www.example.com:8080/some/path'); test('http://www.example.com?queryString'); test('http://www.example.com/some/path?queryString'); test('http://www.example.com:8080/some/path?queryString');
Output for 4.3.0 - 7.2.0
Test FAIL! Test http://www.example.com array ( 0 => 'http://www.example.com', 1 => 'http', 2 => 'www.example.com', ) Test http://www.example.com:8080 array ( 0 => 'http://www.example.com:8080', 1 => 'http', 2 => 'www.example.com', 3 => '8080', ) Test http://www.example.com/some/path array ( 0 => 'http://www.example.com/some/path', 1 => 'http', 2 => 'www.example.com', 3 => '', 4 => '/some/path', ) Test http://www.example.com:8080/some/path array ( 0 => 'http://www.example.com:8080/some/path', 1 => 'http', 2 => 'www.example.com', 3 => '8080', 4 => '/some/path', ) Test http://www.example.com?queryString array ( 0 => 'http://www.example.com?queryString', 1 => 'http', 2 => 'www.example.com', 3 => '', 4 => '', 5 => 'queryString', ) Test http://www.example.com/some/path?queryString array ( 0 => 'http://www.example.com/some/path?queryString', 1 => 'http', 2 => 'www.example.com', 3 => '', 4 => '/some/path', 5 => 'queryString', ) Test http://www.example.com:8080/some/path?queryString array ( 0 => 'http://www.example.com:8080/some/path?queryString', 1 => 'http', 2 => 'www.example.com', 3 => '8080', 4 => '/some/path', 5 => 'queryString', )