<?php
class rout {
public $segments = array();
public $rules = array(
'([a-z0-9_\-]*)([\.a-z0-9]*)' => 's1=$1',
'([a-z0-9_\-]*)/([a-z0-9_\-]*)([\.a-z0-9]*)' => 's1=$1&s2=$2',
'([a-z0-9_\-]*)/([a-z0-9_\-]*)/([a-z0-9_\-]*)([\.a-z0-9]*)' => 's1=$1&s2=$2&s3=$3',
);
public function __construct($uri) {
$this -> parse_uri($uri);
}
public function parse_uri($uri) {
foreach ($this ->rules as $key => $value) {
if(preg_match('~^'. $key .'$~', $uri)) {
$vars = explode('&', preg_replace('~^'. $key .'$~', $value, $uri, 1));
var_dump($vars);
echo 'yes<br/>';
foreach ($vars as $var) {
$segments = explode('=', $var);
$this ->segments[$segments[0]] = $segments[1];
}
}
break;
}
}
}
$uri = 'index.html';
$route = new rout($uri);
var_dump($route->segments);
?>