mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-04 22:47:21 +00:00
[1.x] Patch split filter
This commit is contained in:
committed by
Fabien Potencier
parent
40f703ab40
commit
4c4df962ee
@@ -790,7 +790,7 @@ function twig_join_filter($value, $glue = '', $and = null)
|
|||||||
*/
|
*/
|
||||||
function twig_split_filter(Environment $env, $value, $delimiter, $limit = null)
|
function twig_split_filter(Environment $env, $value, $delimiter, $limit = null)
|
||||||
{
|
{
|
||||||
if (!empty($delimiter)) {
|
if (strlen($delimiter)) {
|
||||||
return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit);
|
return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
{{ baz|split('', 1)|join('-') }}
|
{{ baz|split('', 1)|join('-') }}
|
||||||
{{ baz|split('', 2)|join('-') }}
|
{{ baz|split('', 2)|join('-') }}
|
||||||
{{ foo|split(',', -2)|join('-') }}
|
{{ foo|split(',', -2)|join('-') }}
|
||||||
|
{{ "hello0world"|split('0')|join('-') }}
|
||||||
--DATA--
|
--DATA--
|
||||||
return ['foo' => "one,two,three,four,five", 'baz' => '12345',]
|
return ['foo' => "one,two,three,four,five", 'baz' => '12345',]
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
@@ -17,4 +18,5 @@ one-two-three,four,five
|
|||||||
1-2-3-4-5
|
1-2-3-4-5
|
||||||
1-2-3-4-5
|
1-2-3-4-5
|
||||||
12-34-5
|
12-34-5
|
||||||
one-two-three
|
one-two-three
|
||||||
|
hello-world
|
||||||
Reference in New Issue
Block a user