Skip to content

[String] Documented the new argument of truncate() #13218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions components/string.rst
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,20 @@ Methods to Join, Split, Truncate and Reverse
u('Symfony is great')->slice(-5); // 'great'

// reduces the string to the length given as argument (if it's longer)
u('Lorem Ipsum')->truncate(80); // 'Lorem Ipsum'
u('Lorem Ipsum')->truncate(3); // 'Lor'
u('Lorem Ipsum')->truncate(8, '…'); // 'Lorem I…'
u('Lorem Ipsum')->truncate(3); // 'Lor'
u('Lorem Ipsum')->truncate(80); // 'Lorem Ipsum'
// the second argument is the character(s) added when a string is cut
// (the total length includes the length of this character(s))
u('Lorem Ipsum')->truncate(8, '…'); // 'Lorem I…'
// if the third argument is false, the last word before the cut is kept
// even if that generates a string longer than the desired length
u('Lorem Ipsum')->truncate(8, '…', false); // 'Lorem Ipsum'

.. versionadded:: 5.1

The third argument of ``truncate()`` was introduced in Symfony 5.1.

::

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