Skip to content

Commit 7490ed6

Browse files
author
Nicolas Perraut
authored
Add split() to Stringable class
1 parent 25730a8 commit 7490ed6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/Illuminate/Support/Stringable.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,25 @@ public function explode($delimiter, $limit = PHP_INT_MAX)
193193
{
194194
return collect(explode($delimiter, $this->value, $limit));
195195
}
196+
197+
/**
198+
* Split string by a regular expression.
199+
*
200+
* @param string $pattern
201+
* @param int $limit
202+
* @param int $flags
203+
* @return \Illuminate\Support\Collection
204+
*/
205+
public function split($pattern, $limit = -1, $flags = 0)
206+
{
207+
$keywords = preg_split($pattern, $this->value, $limit, $flags);
208+
209+
if(! $keywords) {
210+
return collect();
211+
}
212+
213+
return collect($keywords);
214+
}
196215

197216
/**
198217
* Cap a string with a single instance of a given value.

0 commit comments

Comments
 (0)