- preg_match: documentation ( source)
- var_export: documentation ( source)
<?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');