note 60493 added to ref.pcre
| From: | alexbodnat012dotn at tdotil | Date: | Mon, 09 Jan 2006 02:45:32 +0000 |
| Subject: | note 60493 added to ref.pcre | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-101430@lists.php.net to get a copy of this message | ||
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;
}
----
Manual Page -- http://www.php.net/manual/en/ref.pcre.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60493
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60493&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60493&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60493&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60493&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60493&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60493&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60493&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60493&report=yes
Search -- http://master.php.net/manage/user-notes.php