SmartString: Open-source string manipulation library with automatic HTML encoding and fluent chainable interface

13 posts by 4 authors in: Forums > CMS Builder
Last Post: September 16   (RSS)

By Dave - September 11 - edited: September 11

Hi All, 

We've just released SmartString v1.1.0, with improved readme docs with examples (inspired by Djulia's post) and new methods (based on Kenny and Djulia's feedback).

We'll include this in the next beta, but you can read about it here: https://github.com/interactivetools-com/SmartString

You can find the changelog here: https://github.com/interactivetools-com/SmartString/blob/main/CHANGELOG.md

Here's the new chainable methods we've added: 

  • add(): Add a value to the current value
  • multiply(): Multiply the current value by a given multiplier
  • textOnly(): Remove HTML tags, decode entities, and trim the string
  • maxWords(): Limit the string to a maximum number of words with optional ellipsis
  • maxChars(): Limit the string to a maximum number of characters with optional ellipsis
  • dateTimeFormat(): Format date and time using default or custom format
  • phoneFormat(): Format phone numbers according to default rules

And some options to customize defaults at the top of your script or in a site init file: 

SmartString::$numberFormatDecimal   = '.';             // Default decimal separator
SmartString::$numberFormatThousands = ',';             // Default thousands separator
SmartString::$dateFormat            = 'Y-m-d';         // Default dateFormat() format
SmartString::$dateTimeFormat        = 'Y-m-d H:i:s';   // Default dateTimeFormat() format
SmartString::$phoneFormat           = [                // Default phoneFormat() formats
    ['digits' => 10, 'format' => '1 (###) ###-####'],
    ['digits' => 11, 'format' => '#-###-###-####'],
];
Thanks for your ongoing feedback.  We'll have another CMSB beta or release with this included soon as well.

Please feel free to post any additional comments or feedback. Everything is a work in progress. Thank you!
Dave Edis - Senior Developer
interactivetools.com

Hi All, 

We've bundled SmartString with the latest CMSB release here:
https://www.interactivetools.com/forum/forum-posts.php?CMSB-v3.72-Released-Sep-16---Multi-Field-Sorting-Admin-Shortcuts-and-Developer-Console-Updates-82869

This means you can call it like this SmartString::new() if you want to use it.

Thanks, everyone for your feedback and help testing!

Dave Edis - Senior Developer
interactivetools.com