@@ -394,16 +394,20 @@ Methods to Join, Split, Truncate and Reverse
394394 u('Lorem Ipsum')->truncate(3); // 'Lor'
395395 u('Lorem Ipsum')->truncate(80); // 'Lorem Ipsum'
396396 // the second argument is the character(s) added when a string is cut
397- // the third argument is TruncateMode::Char by default
398397 // (the total length includes the length of this character(s))
398+ // (note that '…' is a single character that includes three dots; it's not '...')
399399 u('Lorem Ipsum')->truncate(8, '…'); // 'Lorem I…'
400- // use options to keep complete words
401- u('Lorem ipsum dolor sit amet')->truncate(10, '...', TruncateMode::WordBefore); // 'Lorem...'
402- u('Lorem ipsum dolor sit amet')->truncate(14, '...', TruncateMode::WordAfter); // 'Lorem ipsum...'
400+ // the third optional argument defines how to cut words when the length is exceeded
401+ // the default value is TruncateMode::Char which cuts the string at the exact given length
402+ u('Lorem ipsum dolor sit amet')->truncate(8, cut: TruncateMode::Char); // 'Lorem ip'
403+ // returns up to the last complete word that fits in the given length without surpassing it
404+ u('Lorem ipsum dolor sit amet')->truncate(8, cut: TruncateMode::WordBefore); // 'Lorem'
405+ // returns up to the last complete word that fits in the given length, surpassing it if needed
406+ u('Lorem ipsum dolor sit amet')->truncate(8, cut: TruncateMode::WordAfter); // 'Lorem ipsum'
403407
404408.. versionadded :: 7.2
405409
406- The TruncateMode argument for truncate function was introduced in Symfony 7.2.
410+ The `` TruncateMode `` argument for truncate function was introduced in Symfony 7.2.
407411
408412::
409413
0 commit comments