<?php
if (!defined('NB_ROOT')) define('NB_ROOT',realpath(dirname(__FILE__).'/../..'));
-#die($_REQUEST['prod']);
if (!defined('NB_EOL')) define('NB_EOL',defined('NB_PROD') ? '' : "\n");
-#if (!defined('NB_EOL')) define('NB_EOL',"\n");
require_once(realpath(dirname(__FILE__).'/functions.php'));
-#print_r(self::p());
#$nb = new NB(); debug($nb->test());
+/*
+if (empty($_SERVER['DOCUMENT_ROOT'])) var_export([
+ '~0 : 0' => nb::str_match('~0','0'),
+ 'null : 0' => nb::str_match('null','0'),
+ 'null : ""' => nb::str_match('null',''),
+ '!null : ""' => nb::str_match('!null',''),
+ '!~zaz : "zaza"' => nb::str_match('!~zaz','zaza'),
+ '~zaz : "zaza"' => nb::str_match('~zaz','zaza'),
+ 'za* : "zaza"' => nb::str_match('za*','zaza'),
+]);
+*/
if (class_exists('NB')) return;
class NB {
);
#public static function zaza() { return (is_object($this) ? 'TRUE' : 'FALSE'); }
- public static function test() { return 'TEST'; }
+ #public static function test() { return 'TEST'; }
public function __construct($opt = array()) {
foreach ($opt as $k => $v) {
if ( ! array_key_exists($k,$this) ) self::bye("Unknow param $k = `$v`");
}
}
+ public static function str_match($pattern,$string) {
+ $match = false;
+
+ // No empty values
+ if (strcmp($pattern,'')==0 or $pattern=='!' or $pattern=='~') return false;
+
+ // Equal / Not Equal
+ $equal = '=';
+ $not = strpos($pattern,'!')===0 ? true : false;
+ if ($not) $pattern = substr($pattern,1);
+
+ // Regex
+ if (strpos($pattern,'~')===0) {
+ $pattern = substr($pattern,1);
+ $match = preg_match('@'.str_replace('@','\@',$pattern).'@',$string);
+
+ // Match
+ } elseif(preg_match('/['.preg_quote('*?[]!').']/',$pattern)) {
+
+ #if (strpos($pattern,'*') !== false or strpos($pattern,'') !== false
+ $match = fnmatch($pattern,$string);
+ #var_dump($not);
+
+ // Default
+ } else {
+ if (strtolower($pattern)=='null') {
+ $pattern = '';
+ if (!$string) $string = 0;
+ }
+ #debug("$pattern = $string");
+ $match = ($pattern == $string);
+ }
+
+ return (bool)($not ? !$match : $match);
+
+ }
+
} # < Class
-#die(self::ext2mime('csv'));
?>