public static function test_url($url, $pattern, $create_get = true) { if (is_array($pattern)) { $found = false; foreach ($pattern as $p) { $found = route::test_url($url, $p, $create_get); if ($found) { return $found; } } return false; } $testPattern = preg_replace('#\\{(\\w+)\\}#isU', '(\\w+)', $pattern); $testPattern = preg_replace('#\\{\\?(\\w+)\\}#isU', '(\\w*)', $testPattern); $testPattern = preg_replace('#\\{\\[(\\w+)\\]\\}#isU', '(.+)', $testPattern); $testPattern = preg_replace('#\\{\\?\\[(\\w+)\\]\\}#isU', '(.*)', $testPattern); $testPattern = preg_replace('#/#isU', '/*', $testPattern); if (preg_match_all('#^' . $testPattern . '$#', $url, $matches)) { if (!$create_get) { return true; } if (preg_match_all('#\\{(.+)\\}#isU', $pattern, $names)) { unset($matches[0]); if (count($matches) == count($names[1])) { foreach ($names[1] as $key => $get_name) { $name = preg_replace('#\\[(.+)\\]#isU', '$1', $get_name); $name = ltrim($name, '?'); if ($get_name[0] == '?') { if ($matches[$key + 1][0] != '') { $_GET[$name] = $matches[$key + 1][0]; } } else { $_GET[$name] = $matches[$key + 1][0]; } } } } return true; } return false; }