2017 © Pedro Peláez
 

library str

Str is a PHP class that provides convenient, object-oriented operations for string handling and manipulation.

image

mscribellito/str

Str is a PHP class that provides convenient, object-oriented operations for string handling and manipulation.

  • Tuesday, July 26, 2016
  • by mscribellito
  • Repository
  • 1 Watchers
  • 1 Stars
  • 13 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

   _____  _         
  / ____|| |        
 | (___  | |_  _ __
  \___ \ | __|| '__|
  ____) || |_ | |   
 |_____/  \__||_|   

Latest Version on Packagist Software License Total Downloads, (*1)

What is Str?

Str is a PHP class that provides convenient, object-oriented operations for string handling and manipulation. Str provides methods for examining individual characters of the string, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase. A Str is immutable (constant) and its value cannot be changed after creation., (*2)

Requirements

PHP version 5.3 or newer is required., (*3)

Installing

Install via Composer:, (*4)

composer require mscribellito/str

Require:, (*5)

require 'path/to/Str.php';

Example Usage

$lipsum = new Str("Lorem ipsum dolor sit amet");
$search = "ipsum";
if ($lipsum->contains($search)) {
    printf("'%s' contains '%s'", $lipsum, $search);
    // 'Lorem ipsum dolor sit amet' contains 'ipsum'
}

You can also create an instance of Str via a convenient, helper function:, (*6)

$lipsum = Str("Lorem ipsum dolor sit amet");

Chaining

$str = new Str('php');
echo $str->toUpperCase()->concat(' is a popular general-purpose scripting language');
// PHP is a popular general-purpose scripting language

Constructor Summary

Constructor and Description
Str()
Initializes a newly created Str object so that it represents an empty character sequence.
Str(mixed $original)
Initializes a newly created Str object so that it represents the same sequence of characters as the argument; in other words, the newly created string is a copy of the argument string.
Str(mixed $original, int $offset, int $count)
Initializes a newly created Str object so that it contains characters from a substring of the argument string.

Method Summary

Modifier and Type Method and Description
string __toString()
The value of this string is returned.
string charAt(int $index)
Returns the character at the specified index.
int charCodeAt(int $index)
Returns the character ASCII value at the specified index.
int compareTo(string $str)
Compares two strings lexicographically.
int compareToIgnoreCase(string $str)
Compares two strings lexicographically, ignoring case differences.
Str concat()
Concatenates the specified string(s) to the end of this string.
bool contains(string $str)
Returns true if and only if this string contains the specified string.
bool endsWith(string $suffix)
Tests if this string ends with the specified suffix.
bool equals(string $str)
Compares this string to the specified string.
bool equalsIgnoreCase(string $str)
Compares this string to the specified string, ignoring case considerations.
static Str format(string $format)
Returns a formatted string using the specified format string and arguments.
int indexOf(string $str, [int $fromIndex=0])
Returns the index within this string of the first occurrence of the specified string, optionally starting the search at the specified index.
bool isEmpty()
Returns true if and only if length() is 0.
static Str join(string $delimiter, mixed[] $elements)
Returns a new string composed of array elements joined together with the specified delimiter.
int lastIndexOf(string $str, [int $fromIndex=0])
Returns the index within this string of the last occurrence of the specified character, optionally starting the search at the specified index.
int length()
Returns the length of this string.
bool matches(string $regex)
Tells whether or not this string matches the given regular expression.
bool regionMatches(int $toffset, string $str, int $ooffset, int $length, [bool $ignoreCase=false])
Tests if two string regions are equal.
Str replace(string $target, string $replacement)
Returns a string resulting from replacing all occurrences of target in this string with replacement.
Str replaceAll(string $regex, string $replacement)
Replaces each substring of this string that matches the given regular expression with the given replacement.
Str replaceFirst(string $regex, string $replacement)
Replaces the first substring of this string that matches the given regular expression with the given replacement.
Str[] split(string $regex, [int $limit=null])
Splits this string around matches of the given regular expression.
bool startsWith(string $prefix, [int $toffset=0])
Tests if this string starts with the specified prefix, optionally starting the search at the specified index.
Str substring(int $beginIndex, [int $endIndex=null])
Returns a string that is a substring of this string.
string[] toCharArray()
Converts this string to a new character array.
Str toLowerCase()
Converts all of the characters in this string to lower case.
Str toUpperCase()
Converts all of the characters in this string to upper case.
Str trim([string $characterMask=" \t\n\r\0\x0B"])
Returns a string whose value is this string, with any leading and trailing whitespace removed.

Testing

Run tests with vendor/bin/phpunit, (*7)

License

Released under the MIT License. See LICENSE for details., (*8)

The Versions

26/07 2016

dev-master

9999999-dev https://github.com/mscribellito/Str

Str is a PHP class that provides convenient, object-oriented operations for string handling and manipulation.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

string str

26/07 2016

v1.0

1.0.0.0 https://github.com/mscribellito/Str

Str is a PHP class that provides convenient, object-oriented operations for string handling and manipulation.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

string str

14/07 2016

v0.2-beta

0.2.0.0-beta https://github.com/mscribellito/Str

Str is a PHP library that provides convenient, object-oriented operations for string handling and manipulation.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

string str

22/06 2016

v0.1-alpha

0.1.0.0-alpha https://github.com/mscribellito/Str

Str is a PHP library that provides convenient, object-oriented operations for string handling and manipulation.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

string str