$sanitizer->trunc() method

Truncate string to given maximum length without breaking words and with no added visible extras

This is a shortcut to the truncate() sanitizer, sanitizing to nearest word with the more option disabled and the collapseLinesWith set to 1 space (rather than ellipsis).

Available since version 3.0.157.


// basic usage
$string = $sanitizer->trunc(string $str);

// usage with all arguments
$string = $sanitizer->trunc(string $str, $maxLength = 300, array $options = []);



String to truncate

maxLength (optional)int, array

Maximum allowed length in characters, or substitute $options argument here

options (optional)array

See options for truncate() method or specify type option (word, punctuation, sentence, block).

Return value


$sanitizer methods and properties

API reference based on ProcessWire core version 3.0.225

Latest news

  • ProcessWire Weekly #489
    In the 489th issue of ProcessWire Weekly we'll check out what's new in the core this week, share a brand-new recipe of the week, and more. Read on!
    Weekly.pw / 23 September 2023
  • ProcessWire 3.0.226 new main/master version
    After 8 months in development we are excited to bring you ProcessWire 3.0.226 main/master. This version has a ton of great new features, improvements and optimizations, plus more than 100 issue fixes. This post takes an in-depth look at highlights from this great new version.
    Blog / 25 August 2023
  • Subscribe to weekly ProcessWire news

“To Drupal, or to ProcessWire? The million dollar choice. We decided to make an early switch to PW. And in retrospect, ProcessWire was probably the best decision we made. Thanks are due to ProcessWire and the amazing system and set of modules that are in place.” —Unni Krishnan, Founder of PigtailPundits