note 52331 deleted from ref.pcre by colder

From: Date: Mon, 18 Jun 2007 17:51:28 +0000
Subject: note 52331 deleted from ref.pcre by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-127549@lists.php.net to get a copy of this message
Note Submitter: alexbodn at 012 dot n@t dot il ---- Here is a small function to determine whether a string is a [valid] preg expression. 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 false; }

« previous php.notes (#127549) next »