fantomel Posted January 25, 2013 Share Posted January 25, 2013 Hello i have a problem with the following code: $uri = '/index.php/'; $this->finalRegex = '/^' . preg_quote($uri, '/') . '$/'; if(preg_match($this->finalRegex, '/index.php') { echo "works!"; } It returns string(18) "/^\/index\.php\/$/" As you can see it adds a \ before .php which would be inconsistent with the string i'm trying to match ( offered an example). can you help me understand how to fix i tried everything it came in my mind. Quote Link to comment Share on other sites More sharing options...
fantomel Posted January 26, 2013 Author Share Posted January 26, 2013 bump please anyone ? Quote Link to comment Share on other sites More sharing options...
.josh Posted January 26, 2013 Share Posted January 26, 2013 preg_quote escapes all characters in your string that mean something special to the regex engine. The dot is escaped because it is a meta character that matches (almost) any one character. Since you want to match for a literal dot instead of any character, it is escaped. So in other words, it is working as intended. p.s. - If you had read the manual entry for preg_quote, you would have seen this right there at the top. In case you didn't know, php.net has a nifty shortcut to their functions, just go to www.php.net/functionNameHere Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.