diff options
author | Nathan Gass | 2012-03-26 15:20:24 +0000 |
---|---|---|
committer | Nathan Gass | 2012-03-26 15:20:24 +0000 |
commit | 0147e6e3aea620a54b0c3f6c932c658ee72a45a0 (patch) | |
tree | be3570287efdba1219dd1150439e4f739bd95f7a /it.class | |
parent | bbcc6615dc5316a73f07b262950ac18d50c80497 (diff) | |
download | itools-0147e6e3aea620a54b0c3f6c932c658ee72a45a0.tar.gz itools-0147e6e3aea620a54b0c3f6c932c658ee72a45a0.tar.bz2 itools-0147e6e3aea620a54b0c3f6c932c658ee72a45a0.zip |
new utf8 safe functions it::grep and it::substr_replace
Diffstat (limited to 'it.class')
-rw-r--r-- | it.class | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -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 |