本文整理匯總了PHP中route::test_url方法的典型用法代碼示例。如果您正苦於以下問題:PHP route::test_url方法的具體用法?PHP route::test_url怎麽用?PHP route::test_url使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類route
的用法示例。
在下文中一共展示了route::test_url方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: test_url
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;
}