Skip to content

Commit 062b9c3

Browse files
committed
minor #14268 [String] Allow to define slugger substitutions with PHP closures (javiereguiluz)
This PR was merged into the master branch. Discussion ---------- [String] Allow to define slugger substitutions with PHP closures Fixes #14246. Commits ------- b7c8de7 [String] Allow to define slugger substitutions with PHP closures
2 parents b8e8449 + b7c8de7 commit 062b9c3

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

components/string.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,19 @@ that only includes safe ASCII characters::
473473
$slug = $slugger->slug('10% or 5€');
474474
// $slug = '10-percent-or-5-euro'
475475

476+
// for more dynamic substitutions, pass a PHP closure instead of an array
477+
$slugger = new AsciiSlugger('en', function ($string, $locale) {
478+
return str_replace('❤️', 'love', $string);
479+
});
480+
476481
.. versionadded:: 5.1
477482

478483
The feature to define additional substitutions was introduced in Symfony 5.1.
479484

485+
.. versionadded:: 5.2
486+
487+
The feature to use a PHP closure to define substitutions was introduced in Symfony 5.2.
488+
480489
The separator between words is a dash (``-``) by default, but you can define
481490
another separator as the second argument::
482491

0 commit comments

Comments
 (0)