Skip to content

hierone/strings

Repository files navigation

Strings Component

Advanced string manipulation utilities for PHP with comprehensive Unicode support.

Overview

The Strings component provides an object-oriented API for string manipulation, dealing with bytes, UTF-8 code points, and Unicode graphemes. It offers both static utility methods and fluent object-oriented interfaces for maximum flexibility.

Features

  • Static Utilities: Fast static methods for common string operations
  • Fluent Interface: Object-oriented string manipulation with method chaining
  • Unicode Support: Comprehensive Unicode string handling with normalization
  • HTML Safety: HTML-aware string manipulation with proper escaping
  • Inflection: Pluralization, singularization, and text transformation
  • Truncation: Smart text truncation with word preservation

Installation

composer require hierone/strings

Usage

Global Helper Functions

// Create a fluent string object
$result = str('Hello World')->lower()->replace(' ', '-');

// Create a Unicode string
$unicode = u('café')->normalize()->upper();

// Create an HTML-safe string
$html = html('<p>Content</p>')->escape();

Static Utilities

use Hierone\Component\Support\Strings\Str;

$contains = Str::contains('Hello World', 'World');
$slug = Str::lower('Hello World');
$random = Str::random(16);

Object-Oriented Interface

use Hierone\Component\Support\Strings\StringObject;

$string = new StringObject('Hello World');
$result = $string->lower()->replace(' ', '-')->toString();

Unicode Operations

use Hierone\Component\Support\Strings\UnicodeString;

$unicode = new UnicodeString('café', 'UTF-8');
$length = $unicode->graphemeLength(); // Visual character count
$normalized = $unicode->normalize('C');
$reversed = $unicode->reverse();

Requirements

  • PHP 8.2 or higher
  • hierone/depreciation-contracts ^1.0

License

This package is open-sourced software licensed under the MIT license.

About

string manipulation utilities for PHP.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages