3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Application\Router; use Application\Views as Views; class Router { private $request_uri; private $routes = array(); public function __construct($request_uri) { $this->request_uri = $request_uri; /** * Routes go here. * The URI is matched against the routes IN THE ORDER THEY ARE DEFINED! */ $this->addRoute('/\/?events\/?/'); $this->addRoute('/^\/$/'); } public function addRoute($regex) { $this->routes[] = $regex; } public function route() { $match = FALSE; for ($x = 0; $x < count($this->routes); $x ++) { if (preg_match($this->routes[$x], $this->request_uri)) { $match = TRUE; } } if ($match === FALSE) { new Views\FOF(); } else { $v = new Views\Events(); echo $v->blah; } } }

preferences:
44.97 ms | 402 KiB | 5 Q