GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Wuzzitor/StringUtil: Provides a consistent, self-explaining layer to accomplish common string operations.

BranchesTags
Open more actions menu

Latest commit

 

History

31 Commits
31 Commits

Folders and files

NameName
Last commit message
Last commit date
src
src
 
 
tests
tests
 
 
.coveralls.yml
.coveralls.yml
 
 
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 
composer.lock
composer.lock
 
 
phpunit.xml.dist
phpunit.xml.dist
 
 

Repository files navigation

StringUtil

Build Status Coverage Status

Overview

This library provides a consistent, self-explaining layer to accomplish string related tasks.

Speaking method names make string operations more readable and reveal the intention clearly. Please compare the following, common snippets regarding readability:

// Native:
if (strpos($log, 'failure') !== false) {
    // [...]
}

// With StringUtil:
if (StringUtil::contains($log, 'failure')) {
    // [...]
}

In contrast to the built-in PHP string functions, the library provides methods with consistent signatures, which always expect the subject string as first parameter.

Known Restrictions

This library is meant for common, light-weight string operations. It is currently not designed for heavy, complex string tasks such as transparent charset handling.

Installation

Add the following to your composer.json (see getcomposer.org):

"require" :  {
    // ...
    "wuzzitor/string-util": "~1.0"
}

Concept

The library provides a single class (Wuzzitor\StringUtil), whose static methods are the entry points for all string operations.

All methods are stateless to ensure full testability and to avoid code that is hard to debug.

Usage

Example:

use Wuzzitor\StringUtil;

$filename = 'example.php';
$withoutExtension = StringUtil::removeSuffix($filename, '.php);
// $withoutExtension == 'example'

The following signatures show all available operations:

  • StringUtil::startsWith(string $subject, string $prefix) : boolean
  • StringUtil::endsWith(string $subject, string $suffix) : boolean
  • StringUtil::contains(string $subject, string $needle) : boolean
  • StringUtil::containsAny(string $subject, string[] $needles) : boolean
  • StringUtil::containsAll(string $subject, string[] $needles) : boolean
  • StringUtil::removePrefix(string $subject, string $prefix) : string
  • StringUtil::removeSuffix(string $subject, string $suffix) : string
  • StringUtil::replace(string $subject, string $search, string $replace) : string
  • StringUtil::replace(string $subject, array<string, string> $searchReplaceMapping) : string

License

Code released under the MIT license.

About

Provides a consistent, self-explaining layer to accomplish common string operations.

Resources

Readme
MIT license
Activity
Custom properties

Stars

2 stars

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.