Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $routes = array();
- $routes[] = array(":controller/:action", array(
- "controller" => '',
- 'action' => ''));
- $routes[] = array(":controller/:action/(\d+)", array(
- "controller" => '',
- 'action' => '',
- 'id' => 0));
- $routes[] = array(":controller/show/(\d+)", array(
- "controller" => '',
- 'action' => 'show',
- 'id' => 0));
- $routes[] = array(":controller/show/(\d+)/:name", array(
- "controller" => '',
- 'action' => 'show',
- 'id' => 0,
- 'name' => ''));
- //test URLs
- $urlCnt[0] = "/information/location";
- $urlCnt[1] = "/webdesign/show/1";
- $urlCnt[2] = "/information/show/3/why-you-should-choose-us";
- $urlCnt[3] = "/information/delete/3/becauseItsOld";
- //some empty stuff for later
- $params = array();
- $regexContainer = array();
- $regex = "";
- //prepare the regex to parse the urls
- foreach($routes as $route)
- {
- $ga = preg_split("/\//", $route[0] );
- foreach($ga as $expr)
- {
- //check if the name starts with a : - if so than it will be a variable that is needed as an array index
- //important for later stuff, as controller, action, params always be there as an index
- if( strpos($expr, ":") === 0 )
- {
- //:controller or :action found or whatever -> a regex need to be used
- $regex .= "\/[a-zA-Z-0-9]+";
- }
- else
- {
- //not found therefore what is written is the requirement
- $regex .= "\/" . $expr;
- }
- }
- $regexContainer[] = $regex;
- $regex = null;
- }
- //matches
- foreach($regexContainer as $indiRegex)
- {
- print "<h1>" . $indiRegex . "</h1>";
- foreach ($urlCnt as $url)
- {
- if ( preg_match("/^" . $indiRegex . "\z/i", $url ) === 1 )
- {
- print $url . "<br />";
- }
- else
- {
- print "NO:( <br />";
- }
- }
- print "<br />";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement