summaryrefslogtreecommitdiff
path: root/it.class
diff options
context:
space:
mode:
authorUrban Müller2017-03-30 20:53:20 +0200
committerUrban Müller2017-03-30 20:53:20 +0200
commit2672253419813f6457366a66aaf93faea48f43f6 (patch)
tree78767856301d854edb2deeb613913457cc572ea2 /it.class
parenta4f1a3241fda15df244cf77613e1405a8d50810b (diff)
downloaditools-2672253419813f6457366a66aaf93faea48f43f6.tar.gz
itools-2672253419813f6457366a66aaf93faea48f43f6.tar.bz2
itools-2672253419813f6457366a66aaf93faea48f43f6.zip
it::split as frontend for preg_split()
Diffstat (limited to 'it.class')
-rw-r--r--it.class14
1 files changed, 14 insertions, 0 deletions
diff --git a/it.class b/it.class
index a96032f..1403013 100644
--- a/it.class
+++ b/it.class
@@ -454,6 +454,20 @@ static function grep($pattern, $array, $p = array())
return $result;
}
+
+/**
+ * Returns string split by pattern (like preg_split but utf8 and case insensitive)
+ * @param $pattern Regex to match against, no delimiters
+ * @param $subject String to split
+ * @param $p['limit'], $p['no_empty'], $p['delim_capture'], $p['offset_capture'] See preg_split()
+ */
+static function split($pattern, $subject, $p = array())
+{
+ $flags = ($p['no_empty'] ? PREG_SPLIT_NO_EMPTY : 0) | ($p['delim_capture'] ? PREG_SPLIT_DELIM_CAPTURE : 0) | ($p['offset_capture'] ? PREG_SPLIT_OFFSET_CAPTURE : 0);
+
+ return preg_split(it::convertregex($pattern, $p), $subject, $p['limit'] ?: -1, $flags);
+}
+
/**
* Convert string or array to utf8 if it was not already utf-8 before. Also handles double encoding
* @param $value String or array to convert