Skip to content
This repository has been archived by the owner on Mar 3, 2022. It is now read-only.

kbond/string

Repository files navigation

zenstruck/string

Build Status Code Coverage StyleCI Latest Stable Version License

Various string utility functions for PHP. A Twig Extension is available.

Installation

composer require zenstruck/string

Usage

remove_whitespace

Replaces   with a single space and converts multiple sequential spaces into a single space.

$ret = remove_whitespace("  foo     \n\n\n  \r  bar"); // $ret = "foo bar"

null_trim

Similar to core "trim" but returns null instead of an empty string. When an array is passed, all elements get processed recursively.

$ret = null_trim(" foo  bar   "); // $ret = "foo bar"

$ret = null_trim("   "); // $ret = null

$ret = null_trim(array(" foo  bar   ", "   ")); // $ret = array("foo bar", null)

$ret = null_trim("foo / ", "/ "); // $ret = "foo"

truncate_word

Truncates text to a length without breaking words (calls remove_whitespace before truncating).

$ret = truncate_word("      foo       bar  baz", 10); // $ret = "foo bar..."

About

String utilities (null_trim, remove_whitespace, truncate_word)

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages