From ce1ecca5daf86712e7b04e94221f8e17aba84ecf Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Thu, 12 Mar 2015 20:35:08 +0000 Subject: [PATCH] route.php : Add support of URL matching with or without Slash git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2020 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- route.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/route.php b/route.php index 9667100..618a17e 100644 --- a/route.php +++ b/route.php @@ -21,6 +21,8 @@ class route public $debug=0; //public $defaultOutput = "html"; // Default renderer : html + /** Allow slashes in the url when matching the regex */ + public $allowSlashes = true; // Provide the the class catch errors in routing. // Must be provided in an array(class,method); public $errors = null; @@ -316,8 +318,12 @@ class route //$regex = str_replace ("?", "\?", $regex); //$regex = str_replace (".", "\.", $regex); $regex = str_replace ("{", "(?P<", $regex); - $regex = str_replace ("}", ">.+)", $regex); + if ($this->allowSlashes) + $regex = str_replace ("}", ">.+)", $regex); + else + $regex = str_replace ("}", ">[^/]+)", $regex); unset ($matches); +//echo "REGEX=".htmlentities ($regex)." ? URL=".htmlentities ($url); $rcRegex = preg_match ($regex, $url, $matches); if ($rcRegex !== FALSE && $rcRegex !== 0) {