Skip to content

Commit 0f102e4

Browse files
committed
minor #13218 [String] Documented the new argument of truncate() (javiereguiluz)
This PR was merged into the master branch. Discussion ---------- [String] Documented the new argument of truncate() Fixes #13202. Commits ------- 10e97c0 [String] Documented the new argument of truncate()
2 parents 58c9c6f + 10e97c0 commit 0f102e4

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

components/string.rst

+14-3
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)