Skip to content

Commit 10e97c0

Browse files
committed
[String] Documented the new argument of truncate()
1 parent ae1a131 commit 10e97c0

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

components/string.rst

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,20 @@ Methods to Join, Split, Truncate and Reverse
348348
u('Symfony is great')->slice(-5); // 'great'
349349

350350
// reduces the string to the length given as argument (if it's longer)
351-
u('Lorem Ipsum')->truncate(80); // 'Lorem Ipsum'
352-
u('Lorem Ipsum')->truncate(3); // 'Lor'
353-
u('Lorem Ipsum')->truncate(8, '…'); // 'Lorem I…'
351+
u('Lorem Ipsum')->truncate(3); // 'Lor'
352+
u('Lorem Ipsum')->truncate(80); // 'Lorem Ipsum'
353+
// the second argument is the character(s) added when a string is cut
354+
// (the total length includes the length of this character(s))
355+
u('Lorem Ipsum')->truncate(8, '…'); // 'Lorem I…'
356+
// if the third argument is false, the last word before the cut is kept
357+
// even if that generates a string longer than the desired length
358+
u('Lorem Ipsum')->truncate(8, '…', false); // 'Lorem Ipsum'
359+
360+
.. versionadded:: 5.1
361+
362+
The third argument of ``truncate()`` was introduced in Symfony 5.1.
363+
364+
::
354365

355366
// breaks the string into lines of the given length
356367
u('Lorem Ipsum')->wordwrap(4); // 'Lorem\nIpsum'

0 commit comments

Comments
 (0)