Jump to content

preg quote problem


fantomel

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/273635-preg-quote-problem/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/273635-preg-quote-problem/#findComment-1408372
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.