Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $str = "/parent/:dbname/:collname/:id";
- function uri2regex ($str) {
- $word = "([0-9a-zA-Z_-]+)";
- $flag = preg_match_all("/:\w+/",$str, $matches);
- $params = $matches[0];
- array_walk($params, 'uriNormalize');
- var_dump($params);
- $ret = preg_replace("/:\w+/", $word, $str);
- $ret = str_replace("/", "\/", $ret);
- return "/^" . $ret . "/";
- }
- function uriNormalize (&$item) {
- $item = str_replace(":", "", $item);
- }
- $regex = uri2regex($str);
- var_dump($regex);
- $uri = "/parent/foo_db/bar_coll/200";
- $flag = preg_match_all($regex, $uri, $matches);
- var_dump($flag);
- var_dump($matches);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement