Jump to content


Photo

preg quote problem


  • Please log in to reply
2 replies to this topic

#1 fantomel

fantomel

    Advanced Member

  • Members
  • PipPipPip
  • 186 posts

Posted 25 January 2013 - 09:19 AM

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.

#2 fantomel

fantomel

    Advanced Member

  • Members
  • PipPipPip
  • 186 posts

Posted 26 January 2013 - 05:16 AM

bump please anyone ? :D

#3 .josh

.josh

    .josh

  • Administrators
  • 14,746 posts

Posted 26 January 2013 - 09:13 AM

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

Did I help you? Feeling generous? Donate to me! || Donate to phpfreaks!
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com