preg_quote: possible arg addition for regex delimiter escaping

From: Date: Thu, 25 May 2000 19:12:24 +0000
Subject: preg_quote: possible arg addition for regex delimiter escaping
Groups: php.dev 
Request: Send a blank email to php-dev+get-19439@lists.php.net to get a copy of this message
Using the current form of preg_quote, you can not reliably quote a string for use in one of the preg_ functions because, it's always possible for the delimiter you use to be part of the original string passed to preg_quote. An example would be: $regex = preg_quote("http://www.php.net/"); preg_match("/$regex/", $teststr); The above code would return an error because the / in the original string would not be escaped and would be interpreted as a delimiter in the regex string. This isn't a problem if you know exactly what kind of data you will be using in your regex string, but when you do not, you run the risk of using a delimiter that also shows up in the original string. You could get around this by using preg_replace along with preg_quote, but I think a more elegant solution would be to add an extra, optional argument to preg_replace that would allow you to specify an additional character to be quoted along with the others. This would not break current functionality but would add to the usefulness of the function. Also, it would most likely cut down on the number of bug reports that will be generated because of people thinking that the function should also quote the "/" character, the most commonly used Perl regex delimiter... After all that, my question is.. does anyone care? If I add this functionality to php_pcre.c, is it likely to be added to the cvs tree, or will it be ignored? Would anyone, besides me, like to see this functionality added? Your input is appreciated, Daniel Beckham danbeck@dealnews.com dealnews.com, Inc.

« previous php.dev (#19439) next »