summaryrefslogtreecommitdiff
path: root/it.class
diff options
context:
space:
mode:
Diffstat (limited to 'it.class')
-rw-r--r--it.class21
1 files changed, 21 insertions, 0 deletions
diff --git a/it.class b/it.class
index 924f271..f683568 100644
--- a/it.class
+++ b/it.class
@@ -388,6 +388,22 @@ static function replace($replacements, $string, $p = array())
}
/**
+ * Returns only the array elements matching the given regex
+ * @param $pattern Regex to match against
+ * @param $array array to grep
+ * @return New array
+ */
+static function grep($pattern, $array, $p = array())
+{
+ if (!preg_match('/\\\\[wb]|[!\x80-\xff]|\[\[:/i', $pattern) && !$p)
+ $result = preg_grep('!' . $pattern . '!i' . (ini_get('default_charset') == 'utf-8' ? 'u' : ''), $array); # fast path for simple patterns
+ else
+ $result = preg_grep(it::convertregex($pattern, $p), $array);
+
+ return $result;
+}
+
+/**
* Uppercase first character similar to ucfirst() but for mbstring.internal_encoding
*/
static function ucfirst($string)
@@ -403,6 +419,11 @@ static function ucwords($string)
return preg_replace_callback('/\b\w/u', function($m) { return mb_strtoupper($m[1]); }, mb_strtolower($string));
}
+static function substr_replace($string, $replacement, $start, $length)
+{
+ return grapheme_substr($string, 0, $start) . $replacement . grapheme_substr($string, $start + $length);
+}
+
/**
* Extract key => value pairs from assoc array by key
* @param $array array to filter