note 60493 deleted from ref.pcre by colder
| From: | colder@php.net | Date: | Mon, 18 Jun 2007 17:51:12 +0000 |
| Subject: | note 60493 deleted from ref.pcre by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127548@lists.php.net to get a copy of this message | ||
Note Submitter: alexbodn at 012 dot n@t dot il
----
here is an annotation to my note from 28-Apr-2005 03:52, due to the welcome contribution of dipesh
khakhkhar:
Here is a small function to determine whether a string is a preg expression.
Please note, that a dot '.' character in a regexp may match any character, including a
dot, thus a string containing a dot may well be interpreted as an ordinary string, or a regexp.
function preg_ispreg($str)
{
$prefix = "";
$sufix = "";
if ($str[0] != '^')
$prefix = '^';
if ($str[strlen($str) - 1] != '$')
$sufix = '$';
$estr = preg_replace("'^/'", "\\/",
preg_replace("'([^/])/'", "\\1\\/", $str));
if (@preg_match("/".$prefix.$estr.$sufix."/", $str, $matches))
return strcmp($str, $matches[0]) != 0;
return true;
}