PHP Classes

Stringizer: Manipulate multibyte text strings as objects

Recommend this page to a friend!
  Info   View files Documentation   View files View files (166)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2022-10-21 (23 days ago) RSS 2.0 feedStarStarStarStar 67%Total: 306 This week: 6All time: 7,317 This week: 135Up
Version License PHP version Categories
stringizer 1.0.45MIT/X Consortium ...5.6PHP 5, Text processing
Description Author

This package can manipulate multibyte text strings as objects.

It can take a given string and perform one or more manipulation operations through a fluent interface.

Currently it provides the following functions:

- Camelize
- Concat
- Contains & Contains Case-Insensitive
- Contains Count & Count Case-Insensitive
- Dasherize
- EndsWith
- StartsWith
- EnsureLeft
- EnsureRight
- HashCode
- IndexOf & IndexOf Case-Insensitive
- IsAlpha
- IsAlphaNumeric
- IsAlphaNumeric with Space
- IsAlphaNumeric with Space and Dash
- IsDate
- IsDecimal
- IsEmail
- IsEmpty
- IsNumber
- LastIndexOf & LastIndexOf Case-Insensitive
- Length
- Lowercase
- Lowercase First
- Pad Both
- Pad Left
- Pad Right
- Replace Accents
- Remove Non Ascii
- Remove Whitespace
- Replace & Replace Case-Insensitive
- Reverse
- Split
- Strip Punctuation
- Strip Tags
- Sub String
- Trim
- Trim Left
- Trim Right
- Truncate
- Truncate Match and Truncate Match Case-Insensitive
- Uppercase
- Uppercase Words
- Width

Innovation Award
PHP Programming Innovation award nominee
June 2016
Number 5
PHP provides a nice set of built-in functions for manipulating text strings.

When you need to manipulate text strings that use multibyte encodings, you can to use the mb_string extension but it only provides a limited number of functions.

This package wraps around the mb_string extension to provide a much more extensive set of string manipulation functions.



Manuel Lemos
Picture of jasonlam604x
Name: jasonlam604x <contact>
Classes: 1 package by
Country: Canada Canada
Innovation award
Innovation award
Nominee: 1x

Details

<!-- Title: Stringizer Description: Stringizer is a PHP string manipulation library with support for method chaining and multibyte handling Author: jasonlam604 --> <meta name='keywords' content='string,manipulation,chaining,multibyte,php,transformer,stringizer'>

Stringizer

Stringizer is a PHP string manipulation library with support for method chaining and multibyte handling

Latest Stable Version Total Downloads Monthly Downloads Build Status Coverage Status License: MIT

Basic Functions

String Functions * Base64Encode * Base64Decode * Between * Camelize * CamelToSnake * CharAt * Chars * ChompLeft - deprecated * ChompRight - deprecated * ChopLeft * ChopRight * CollapseWhitespace * Concat * Contains & Contains Case-Insensitive * Contains Count & Count Case-Insensitive * Dasherize * Delete * EndsWith * EnsureLeft * EnsureRight * First * HasLowerCase * HasUpper * HashCode * IndexOf & IndexOf Case-Insensitive * IsAscii * IsAlpha * IsAlphaNumeric * IsAlphaNumeric with Space * IsAlphaNumeric with Space and Dash * IsBase64 * IsBlank * IsDate * IsDecimal * IsEmail * IsEmpty * IsHash * IsHexColor * IsHexDecimal * IsIsbn10 * IsIsbn10 * IsIpv4 * IsIpv6 * IsJson * IsNumber * IsMultiByte * IsLatitude * IsLongitude * IsRgbColor * IsSemver * IsUrl * Join * Last * LastIndexOf & LastIndexOf Case-Insensitive * Length * LineCount * Lowercase * Lowercase First * Pad Both * Pad Left * Pad Right * RandomAlpha * RandomNumeric * RandomAlphaNumeric * Replace Accents * Remove Non Ascii * Remove Whitespace * Repeat * Replace & Replace Case-Insensitive * Reverse * SentenceCount * Split * StartsWith * Strip Punctuation * Strip Tags * Sub String * SwapCase * ToBoolean * Trim * Trim Left * Trim Right * Truncate * Truncate Match & Truncate Match Case-Insensitive * Uppercase * Uppercase Words * Width * WordCount

Overview

Stringizer is a string library made up of existing PHP multibyte-string functions and a variety of string manipulation solutions found on Stackoverflow.com. The intent is to save you time looking up string maninpulation solutions yourself and provide the convience of method chaining. Awarded the Innovation Award in June 2016 from PHPClasses.org.

PSR Compliance and Code Quality: * PSR-0: Autoloading Standard * PSR-1: Basic Coding Standard * PSR-2: Coding Style * PSR-4: Autoloader * Semver Versioning * 100% Unit Test Coverage, results by Coveralls.io * Platinum Code Quality Analysis by SensioLabsInsight * Continuous Integration and regression unit testing using Travis CI

Key Highlights

  • Built in Multibyte support, where applicable and possible
  • Chaining of functions
  • In some case removing the hassle of you trying to figure out the right regex solution

Version

Latest Stable Version

Installation

It's recommended that you use Composer to install Stringizer.

Manual install with composer

$ composer require jasonlam604/stringizer "^2.14.0"

Using the composer.json file

"require": {
    "jasonlam604/stringizer": "^2.14.0"
}

This will install Stringizer and all required dependencies. Stringizer requires PHP 5.6.0 or newer.

Usage

Sample usage:

<?php

// Composer Autoloader
require 'vendor/autoload.php';

use Stringizer\Stringizer;

$s = new Stringizer("myapp");

$s->ensureRight("/");

// The following outputs: myapp/
echo $s->getString(); 

Tests

To execute the test suite, you'll need phpunit.

$ phpunit

Submit Issues

Feel free to open any Issues, Bugs or suggestions!

Contributing

Accepting Pull-Requests!

Credits

License

The Stringizer is licensed under the MIT license. See License File for more information.

String Functions

base64Decode

Bae64 decode string

$s = new Stringizer("44GT44KT44Gr44Gh44Gv");
$s->base64Decode(); // ?????

base64Encode

Base64 Encode String

$s = new Stringizer("???Íñ?ìz??");
$s->base64Encode(); // yJjFpsWXw43DscSdw6x6xJXFlQ==

between

Extracts a string between left and right strings.

$s = new Stringizer("<div>???Íñ?ìz??</div>");
$s->between("<div>", "</div>"); // ???Íñ?ìz??

camelize

Removes any underscores or dashes and converts a string into camel case.

$s = new Stringizer("data_rate");
$s->camelize(); // dataRate

camelToSnake

Converts Camel case to Snake Case.

$s = new Stringizer("helloS??Íñ?ìz??");
$s->camelToSnake(); // hello_s??Íñ?ìz??

charAt

Obtain character at specific position in a string where the first position is consider 0.

$s = new Stringizer("Foo Bar Fizz Buzz");
$s->charAt(4); // B

chars

Return the given string as an array where each index contains a character.

$s = new Stringizer("???Íñ?ìz??");
$s->chars(); // an array made up 10 indexes ["?","?","?","Í","ñ","?","ì","z","?","?"]

$s = new Stringizer("???Íñ?ìz??");
$s->charAt(1); // ?

$s = new Stringizer("???Íñ?ìz??");
$s->charAt(0); // S

chompLeft

Deprecated - Removes prefix from start of string.

$s = new Stringizer("???Íñ?ìz??");
$s->chompLeft("???Íñ?"); // ìz??

chompRight

Deprecated - Removes suffix from start of string.

$s = new Stringizer("???Íñ?ìz??");
$s->chompRight("ìz??"); // ???Íñ?

chopLeft

Removes prefix from start of string.

$s = new Stringizer("???Íñ?ìz??");
$s->chopLeft("???Íñ?"); // ìz??

chopRight

Removes suffix from start of string.

$s = new Stringizer("???Íñ?ìz??");
$s->chopRight("ìz??"); // ???Íñ?

collapseWhitespace

Remove extra whitespace, leave only one whitespace between characters where there is more then one whitespace value.

$s = new Stringizer(""???Íñ?\n\nìz?? \n\t    \r"");
$s->concat("collapseWhitespace") // ???Íñ? ìz??

concat

Combine string values.

Combine at end of the string.

$s = new Stringizer("fizz");
$s->concat(" buzz") // fizz buzz

Combine at the beginning of the string by passing in the boolean value true in the optional second parameter.

$s = new Stringizer(" buzz");
$s->concat("fizz",true) // fizz buzz
contains

Search for string within another string, return true if found else return false

$s = new Stringizer("fizz buzz foo bar");
$s->contains("buzz"); // true

$s = new Stringizer("fizz buzz foo bar");
$s->contains("Buzz"); // false, case sensitive

$s = new Stringizer("fizz buzz foo bar");
$s->containsIncaseSensitive("Buzz"); // true, case insensitive

containsCount

Count the number of string occurrences

$s = new Stringizer("fizz buzz fizz buzz fizz buzz");
$s->containsCount("buzz"); // 3

$s = new Stringizer("fizz buzz fizz buzz fizz buzz");
$s->containsCount("nomatch"); // 0

$s = new Stringizer("fizz buzz foo bar");
$this->assertEquals(0, $s->containsCount("BUZZ")); // 0, case sensitive no match found

$s = new Stringizer("fizz buzz foo bar");
$s->containsCountIncaseSensitive("BUZZ"); // 1, case in-sensitive 1 match found

$s = new Stringizer("?????? ?????? ?????? ??????");
$this->assertEquals(4, $s->containsCount("?")); // 4

dasherize

Break up a camelize string and seperate with dashes

$s = new Stringizer("dataRate");
$s->dasherize(); // data-rate

delete

Delete runes in str matching the pattern, similiar to the delete string feature in Ruby

$s = new Stringizer("Fizz ?Fizz? Fizz");
$s->delete("?"); //Fizz Fizz Fizz

endsWith

Checks if a string ends with the given suffix.

$s = new Stringizer("Fizz Buzz");
$s->endsWith("zz"); // true

$s = new Stringizer("??????");
$s->endsWith("?"); // true

$s = new Stringizer("??????");
$s->endsWith("????"); // false

ensureLeft

Ensure string starts with prefix

$s = new Stringizer("/myapp");
$s->ensureLeft("/"); //  /myapp

ensureRight

Ensure string ends with suffix

$s = new Stringizer("/myapp");
$s->ensureRight("/"); //  /myapp/

first

Grabs a section from the beginning of the string, the size of the section is determine by the given indicated value.

$s = new Stringizer("???Íñ?ìz??");
$s->first(6); // ???Íñ?

hashCode

Determine the hashcode of a string, algorithm matches the hashCode method available in a Java String class

$s = new Stringizer("Hello, World");
$s->hashCode(); // -505841268

hasLowercase

Checks if value is contains only lowercase values.

$s = new Stringizer("st?iñ?ìz??");
$s->hasLowercase()); // true

$s = new Stringizer("sT?iñ?ìz??");
$s->hasLowercase()); // false

hasUppercase

Checks if value is contains only uppercase values.

$s = new Stringizer("STÃÑ");
$s->hasUppercase()); // true

$s = new Stringizer("StÃÑ");
$s->hasUppercase()); // false

indexOf

Finds position of first occurrence of a string within another.

$s = new Stringizer("Fizz Buzz Foo Bar");
$s->indexOf("Foo"); // 10

If no match is found boolean false is returned.

$s = new Stringizer("Fizz Buzz Foo Bar");
$s->indexOf("bad"); // false

There is a second optional parameter, position offset where to begin the search where left most value is index 0.

$s = new Stringizer("Foo Buzz Foo Bar");
$s->indexOf("Foo", 0); // 0, since offset starts at zero the first Foo is found at index 0
$s->indexOf("Foo", 1); // 9, since offset is past zero the next available match is at index 9

MultiByte

$s = new Stringizer("fòô bà?");
$s->indexOf("bà?"); // 4

Case In-sensitive

$s = new Stringizer("Fizz Buzz Foo Bar");
$s->indexOfCaseInsensitive("foo"); // 10

isAscii

Checks if value contains valid ASCII values only. Optional parameter to allow only printable characters

$s = new Stringizer("abcdefghi....12334567890....ABC..XY!!!@#$%^&*()_+=-<>?:;/.,~][}{\|'");
$s->isAscii(); // true

$s = new Stringizer("\x19test\x7F");
$s->isAscii(); // true
$s->isAscii(true); // false

isAlpha

Checks if value is contains alpha values only.

$s = new Stringizer("FooBar");
$s->isAlpha(); // true

$s = new Stringizer("Foo Bar");
$s->isAlpha(); // false

isAlphaNumeric

Checks if value is contains alphanumeric values only

$s = new Stringizer("F00Bar");
$s->isAlphaNumeric(); // true

$s = new Stringizer("F00 Bar");
$s->isAlphaNumeric(); // false

isAlphaNumericSpace

Checks if value is contains alphanumeric values only including space(s).

$s = new Stringizer("F00 Bar");
$s->isAlphaNumericSpace(); // true

$s = new Stringizer("F00 Bar !");
$s->isAlphaNumericSpace(); // false

isAlphaNumericSpaceDash

Checks if value is contains alphanumeric values only including space(s) and dash(es).

$s = new Stringizer("Marie-Anne Lucy");
$s->isAlphaNumericSpaceDash(); // true

$s = new Stringizer("Marie-Ann Lucy!");
$s->isAlphaNumericSpaceDash(); // false

isBase64

Checks if value is a valid Base64 string

// Decoded value is ???Íñ?ìz??
$s = new Stringizer("yJjFpsWXw43DscSdw6x6xJXFlQ==");
$s->isBase64(); // true

isBlank

Checks if value is blank (alias to isEmpty), if string contains whitespace only it is considered empty.

$s = new Stringizer("\n  \n\r\t   ");
$s->isBlank(); // true

isDate

Checks if value is valid date based on the PHP function strtotime.

Requirement, default timezone must be set first

date_default_timezone_set('America/Vancouver');
$s = new Stringizer("2015-03-15");
$s->isDate(); // true

date_default_timezone_set('America/Vancouver');
$s = new Stringizer("January 1st");
$s->isDate(); // true

isDecimal

Checks if value is contains decimal value, whole numbers are considered valid.

$s = new Stringizer("19.99");
$s->isDecimal(); // true

$s = new Stringizer("19");
$s->isDecimal(); // true

$s = new Stringizer("19x");
$s->isDecimal(); // false

isEmail

Checks if value is a valid email.

$s = new Stringizer("John.Doe@fake.com");
$s->isEmail(); // true

$s = new Stringizer("John.Doe@fake@.com");
$s->isEmail(); // false

isEmpty

Checks if value is empty, if string contains whitespace only it is considered empty.

$s = new Stringizer("\n  \n\r\t   ");
$s->isEmpty(); // true

isHash

Checks if value is empty, if string contains whitespace only it is considered empty.

$s = new Stringizer("3ca25ae354e192b26879f651a51d92aa8a34d8d3");
$s->isHash("sha1"); // true

$s->setString("3ca25ae354e192b26879f651a51d92aa8a34d8d3");
$s->isHash("Tiger160"); // true

$s->setString("579282cfb65ca1f109b78536effaf621b853c9f7079664a3fbe2b519f435898c");
$this->assertEquals(true, $s->isHash("sha256"); // true

$s->setString("bf547c3fc5841a377eb1519c2890344dbab15c40ae4150b4b34443d2212e5b04aa9d58865bf03d8ae27840fef430b891");
$this->assertEquals(true, $s->isHash("sha384"); // true

$s->setString("45bc5fa8cb45ee408c04b6269e9f1e1c17090c5ce26ffeeda2af097735b29953ce547e40ff3ad0d120e5361cc5f9cee35ea91ecd4077f3f589b4d439168f91b9");
$this->assertEquals(true, $s->isHash("sha512"); // true

$s->setString("46fc0125a148788a3ac1d649566fc04eb84a746f1a6e4fa7");
$this->assertEquals(true, $s->isHash("tiger192"); // true

isHexColor

Checks if value is valid Hex Color.

$s = new Stringizer("CCDDEE");
$s->isHexColor(); // true

$s = new Stringizer("#CCDDEE");
$s->isHexColor(); // false

$s = new Stringizer("ZZZZZZ");
$s->isHexColor(); // false

isHexDecimal

Checks if value is hexdecimal.

$s = new Stringizer("AB10BC99");
$s->isHexDecimal(); // true

isIsbn10

Determines if value is valid ISBN10

$s = new Stringizer("ISBN:0-306-40615-2");
$s->isIsbn10() // true

isIsbn13

Determines if value is valid ISBN13

$s = new Stringizer("ISBN:979-1-090-63607-1");
$s->isIsbn13() // true

isIPv4

Checks if value is a valid IP, IPv4.

$s = new Stringizer("192.168.1.1");
$s->isIpv4() // true

isIPv6

Checks if value is a valid IP, IPv6.

$s = new Stringizer("2001:cdba:0000:0000:0000:0000:3257:9652");
$s->isIpv6() // true

isJson

Determines if value is valid JSON

$s = new Stringizer("{\"foo\" : {
 \"bar\" : \"Hello\",
 \"baz\" : [ \"quuz\", \"norf\" ]
}}");
$s->isJson() // true

isNumber

Checks if value is a whole number, can be a negative number but can not be a decimal number.

$s = new Stringizer("1234");
$s->isNumber() // true

isMultiByte

Checks if value is MultiByte

$s = new Stringizer("???Íñ?ìz??");
$s->isMultiByte() // true

$s = new Stringizer("Stringizer");
$s->isMultiByte() // false

isLatitude

Checks if value is valid Latitude value

$s = new Stringizer("37.138");
$s->isLatitude() // true

$s = new Stringizer("-91");
$s->isLatitude() // false

isLongitude

Checks if value is valid Longitude value

$s = new Stringizer("190");
$s->isLongitude() // true

$s = new Stringizer("191");
$s->isLongitude() // false

isRgbColor

Checks if value is valid RGB Color

$s = new Stringizer("rgb(255,255,255)");
$s->isRgbColor() // true

isSemver

Checks if value is a valid semver format, see http://semver.org/

$s = new Stringizer("FooBar");
$s->isSemver(); // false

$s = new Stringizer("1.0.0");
$s->isSemver(); // true

$s->setString("1.0.0-3.14.6");
$s->isSemver(); // true

$s->setString("0.0.1-beta");
$s->isSemver(); // true

$s = new Stringizer("1.0");
$s->isAlpha(); // false

isUrl

Checks if value is contains a valid URL

$s = new Stringizer("https://github.com");
$s->isUrl(); // true

join

Concatenates the elements of a to create a single string. The separator string sep is placed between elements in the resulting string. If there is an existing value it is over-written. Default seperator is a comma, if no separator is required then use a blank string.

Uses default separator a comma

$s = new Stringizer("original-string-overwritten");
$s->join(array("Hello","World","Again")); // Hello,World,Again

Uses a pipe as the separator

$s = new Stringizer("");
$s->join(array("?","?","?","?","?"), "|") // ?|?|?|?|?

No separator, use of a blank strinng

$s = new Stringizer("");
$s->join(array("?","?","?","?","?"), "") // ?????

last

Grabs a section from the end of the string, the size of the section is determine by the given indicated value.

$s = new Stringizer("???Íñ?ìz??");
$s->last(4); // ìz??

lastIndexOf

Finds position of last occurrence of a string within another

$s = new Stringizer("Foo Buzz Foo Bar");
$s->lastIndexOf("Foo"); // 9

If no match is found boolean false is returned.

$s = new Stringizer("Fizz Buzz Foo Bar");
$s->lastIndexOf("bad"); // false

There is a second optional parameter, position offset where to begin the search where left most value is index 0.

$s = new Stringizer("Foo Buzz Foo Bar");
$s->lastIndexOf("Foo", 0); // 9 
$s->lastIndexOf("Foo", 4)); // 9
$s->lastIndexOf("Foo", 10)); // false

MultiByte

$s = new Stringizer("fòô bà? fòô bà? fòô bà?");
$s->lastIndexOf("fòô"); // 16

Case In-sensitive

$s = new Stringizer("Fizz Buzz Foo Bar");
$s->lastIndexOf("foo"); //false
$s->lastIndexOfCaseInsensitive("foo"); // 10

length

Find the length of the string

$s = new Stringizer("FizzBuzz");
$s->length(); // 8

Multibyte

$s = new Stringizer("??????");
$s->length(); // 6

lineCount

Count the number of lines based line feed, \n.

$s = new Stringizer("???Íñ?ìz??\n???Íñ?ìz??\n???Íñ?ìz??");
$s->lineCount(); // 2

lowercase

Ensure the string is entirely lower case

$s = new Stringizer("FiZZ");
$s->lowercase(); // fizz

lowercaseFirst

First letter of the string is lower cased

$s = new Stringizer("FiZz");
$s->lowercaseFirst(); // fIZZ

padBoth

Pad string on both sides with indicated value

Padding with an even amount

$s = new Stringizer("fizz");
$s->padBoth("x", 10); // xxxfizzxxx

Padding with an odd amount, the extra character is addded to the end of the string

$s = new Stringizer("fizz");
$s->padBoth("x", 11); // xxxfizzxxxx

padLeft

Pad string on left side with indicated string value and number of times to pad with

$s = new Stringizer("10");
$s->padLeft("0", 5); // 00010

padRight

Pad string on right side with indicated string value and number of times to pad with

$s = new Stringizer("Alien");
$this->assertEquals("Alien     ", $s->padRight(" ", 10)); // "Alien     " 

randomAlpha

Generate a random alpha value, default length of 10 characters.

$s = new Stringizer("");
$s->randomAlpha(); // aYvPXitjCJ

$s = new Stringizer("");
$s->randomAlpha(20); // cmbOUofxAvWeyMGgPHK

randomNumeric

Generate a random string value containing only numeric values, default length of 10 characters. It is important to note this is a string value because otherwise if a value with leading zeros such as 0123456789 would then be 123456789 as type int; but, then would not be length of 10 characters (or the desired indicated expected length)

$s = new Stringizer("");
$s->randomNumeric(); // 8277761361

randomAlphaNumeric

Generate a random alphanumeric value, default length of 10 characters.

$s = new Stringizer("");
$s->randomAlphanumeric(); // w5quanvlUP

repeat

Returns a string repeated n times.

$s = new Stringizer("FizzöBuzz");
$s->repeat(2); // FizzöBuzzFizzöBuzz

$s = new Stringizer("?");
$s->repeat(5); // ?????

replaceAccents

Replace characters with accents with the same character without accents.

$s = new Stringizer("FizzöBuzz Fizz Buzz Fizz Buzzé");
$s->replaceAccents(); // FizzoeBuzz Fizz Buzz Fizz Buzze

$s = new Stringizer("???Íñ?ìz??");
$s->replaceAccents(); // STrIngizer

removeAscii

Remove non Ascii characters

$s = new Stringizer("FizzöBuzz Fizz Buzz Fizz Buzzé");
$s->removeNonAscii(); // FizzBuzz Fizz Buzz Fizz Buzz

removeWhitespace

Remove any whitespace from the string (before, after and any in between)

$s = new Stringizer("Fizz Buzz Fizz Buzz Fizz Buzz");
$s->removeWhitespace(); // FizzBuzzFizzBuzzFizzBuzz

$s = new Stringizer(" ? ? ? Í ñ ? ì z ? ? ");
$s->removeWhitespace(); // ???Íñ?ìz??

replace

Match and replace string(s)

$s = new Stringizer("Fizz Buzz Fizz Buzz Fizz Buzz");
$s->replace("Buzz", "Bar"); // Fizz Bar Fizz Bar Fizz Bar

Multiple replace

$s = new Stringizer("Fizz Buzz Fizz Buzz Fizz Buzz");
$s->replace(array("Fizz","Buzz"), array("Foo","Bar")); // Foo Bar Foo Bar Foo Bar

No Match NOT Case-Insensitive

$s = new Stringizer("Fizz Buzz Fizz Buzz Fizz Buzz");
$s->replace("buzz", "bar"); // Fizz Buzz Fizz Buzz Fizz Buzz
    

Match Case-Insensitive

$s = new Stringizer("Fizz Buzz Fizz Buzz Fizz Buzz");
$s->replaceIncaseSensitive("buzz", "bar"); // Fizz bar Fizz bar Fizz bar

MultiByte

$s = new Stringizer("Fizz?Buzz?Fizz?Buzz?Fizz?Buzz");
$s->replace("?", " "); // Fizz Buzz Fizz Buzz Fizz Buzz

reverse

$s = new Stringizer("mood");
$s->reverse(); // doom

MultiByte


$s = new Stringizer("??????");
$s->reverse(); // ??????

sentenceCount

Count the number of sentences based sentences ending with one the following: . ! or ?

$s = new Stringizer("???Íñ?ìz?? jumped over the stringy stick. ???Íñ?ìz?? jumped over the stringy stick again!  Or did it?");
$s->sentenceCount(); // 3

split

Explode string into an array default delimiter is comma

$s = new Stringizer("Fizz Buzz");
$array = $s->split(" "); // array( 0 => "Fizz", 1 => "Buzz")

$s = new Stringizer("??????");
$array = $s->split("?"); // array( 0 => "???", 1 => "??)

startsWith

Checks if a string starts with the specified suffix.

$s = new Stringizer("Fizz Buzz");
$s->startsWith("Fizz B"); // true

$s = new Stringizer("??????");
$s->startsWith("?"); // true

$s = new Stringizer("??????");
$s->startsWith("????"); // false

stripPunctuation

Remove all of the punctuation

$s = new Stringizer("Hello World! It's me #stringizer");
$s->stripPunctuation(); // Hello World Its me stringizer
  
$s = new Stringizer("-=!'\",?!Hello World][");
$s->stripPunctuation(); // Hello World

stripTags

Remove HTML and PHP tags from a string

$s = new Stringizer("<html>Hello</html>");
$s->stripTags(); // Hello
   
$s = new Stringizer("<html><b>???????</b></html>");
$s->stripTags(); // ???????
 

Optional second paramter to ignore tags (tags not to be to removed)

    
$s = new Stringizer("<html>Hello <b>World</b></html>");
$s->stripTags("<b>"); // Hello <b>World</b>

$s = new Stringizer("<html><head><title>title</title></head><body>Hello <b><span class='fake-class'>World</span></b> ???????</body></html>");
$s->stripTags(); // titleHello World ???????

substring

Find a portion of a string based on postioning (index position in the string) and length of the portion

$s = new Stringizer("Fizz Buzz Foo Bar");
$s->subString(0, 4); // Fizz

$s = new Stringizer("Fizz Buzz Foo Bar");
$s->subString(5, 4)); // Buzz

$s = new Stringizer("Fizz Buzz Foo Bar");
$s->subString(5, 4)); // Buzz

MultiByte

$s = new Stringizer("?????? ??????");
$s->subString(7); // ??????

swapCase

Swap the case of each character.

$s = new Stringizer("hELLO wORLD");
$s->swapCase(); // Hello World

toBoolean

Converts a logical truth string to boolean.

(new Stringizer(true))->toBoolean(); // true
(new Stringizer(false))->toBoolean(); // false
(new Stringizer("stringizer"))->toBoolean(); // false
(new Stringizer("true"))->toBoolean(); // true
(new Stringizer("false"))->toBoolean(); // false
(new Stringizer("TRUE"))->toBoolean(); // true
(new Stringizer("FALSE"))->toBoolean(); // false
(new Stringizer("on"))->toBoolean(); // true
(new Stringizer("off"))->toBoolean(); // false
(new Stringizer("ON"))->toBoolean(); // true
(new Stringizer("OFF"))->toBoolean(); // false
(new Stringizer("yes"))->toBoolean(); // true
(new Stringizer("no"))->toBoolean(); // false
(new Stringizer("YES"))->toBoolean(); // true
(new Stringizer("NO"))->toBoolean(); // false
(new Stringizer(""))->toBoolean(); // false
(new Stringizer(null))->toBoolean(); // false
(new Stringizer(1))->toBoolean(); // true
(new Stringizer(-1))->toBoolean(); // false

trim

Remove whitespace both right and left side of the string

$s = new Stringizer("\x20\x20\x20   ??????fizz???? ??????   ");
$s->trim(); // ??????fizz???? ??????

trimLeft

Remove whitespace left of the string

$s = new Stringizer("\x20\x20\x20   ??????fizz???? ??????   ");
$s->trimLeft()); // ??????fizz???? ??????   

trimRight

Remove whitespace right of the string

$s = new Stringizer("\x20\x20\x20   ??????fizz???? ??????   ");
$s->trimRight(); // \x20\x20\x20   ??????fizz???? ??????

truncate

Shorten right side of string by the specified indicated amount

$s = new Stringizer("fòô bà?");
$s->truncate(4); // fòô

$s = new Stringizer("FizzBuzz");
$s->truncate(4); // Fizz

truncateMatch

Shorten string left or right side if given substring is match

$s = new Stringizer("fòô bà?");
$s->truncateMatch(" bà?"); // fòô

$s = new Stringizer("FizzBuzzFooBar");
$s->truncateMatch("Foo"); // FizzBuzz

Case In-sensitive

$s = new Stringizer("FizzBuzzFooBar");
$s->truncateMatchCaseInsensitive("foo"); // FizzBuzz

uppercase

Ensure entire string is uppercase

$s = new Stringizer("fIzz");
$s->uppercase(); // FIZZ

uppercaseWords

Ensure entire string is uppercase

$s = new Stringizer("fizz buzz foo bar");
$s->uppercaseWords(); // Fizz Buzz Foo Bar

width

Find the width of the string this is different then length for multibyte strings

$s = new Stringizer("??????");
$s->width(); // 12, note multi-byte characters take up more space, typice 2 for each character

$s = new Stringizer("FizzBuzz");
$s->length(); // 8

wordCount

Count the number of words.

$s = new Stringizer("???Íñ?ìz?? ????? ???Íñ?ìz?? ????? ???Íñ?ìz??");
$s->wordCount(); // 5

Basic Functions

setstring

Setting the string you want to apply string manipulations on, this will set the orginal value as well.

$s = new Stringizer("dummy-value");
$s->setString("new-dummy-value");

#### getstring

Retrieve the string in its most current state

$s = new Stringizer("dummy-value"); $s->getString();


#### getStringOriginal

Retrieve the string state prior to any string manipulations

$s = new Stringizer("dummy-value"); $s->getStringOriginal();


#### __toString

Retrieve the string in its most current state

$s = new Stringizer("dummy-value"); echo ($s); // this will output current state, defaults to using the PHP built __toString method


#### setEncoding

Set encoding, behind the scences PHP function mb_internal_encoding is applied

$s = new Stringizer("dummy-value"); $s->setEncoding("UTF-8"); $s->getEncoding(); // UTF-8


#### getEncoding

$s = new Stringizer("dummy-value"); $s->getEncoding(); // Outputs your default encoding based mb_internal_encoding

  Files folder image Files  
File Role Description
Files folder imagesrc (1 file, 1 directory)
Files folder imagetests (81 files)
Accessible without login Plain text file composer.json Data src
Accessible without login Plain text file LICENSE.md Lic. License
Accessible without login Plain text file phpunit.xml Data src
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file _config.yml Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageTransformers (79 files)
  Plain text file Stringizer.php Class src

  Files folder image Files  /  src  /  Transformers  
File Role Description
  Plain text file Alpha.php Class src
  Plain text file AlphaNumeric.php Class src
  Plain text file AlphaNumericSpace.php Class src
  Plain text file AlphaNumericSpaceDash.php Class src
  Plain text file Ascii.php Class Class source
  Plain text file Base64.php Class Class source
  Plain text file Base64Check.php Class Class source
  Plain text file Between.php Class Class source
  Plain text file BooleanConverter.php Class Class source
  Plain text file Camelize.php Class src
  Plain text file CamelToSnake.php Class Class source
  Plain text file Chars.php Class Class source
  Plain text file ChopLeft.php Class Class source
  Plain text file ChopRight.php Class Class source
  Plain text file CollapseWhitespace.php Class Class source
  Plain text file Concat.php Class src
  Plain text file Contains.php Class src
  Plain text file Dasherize.php Class src
  Plain text file Date.php Class src
  Plain text file Decimal.php Class src
  Plain text file Email.php Class src
  Plain text file EmptyCheck.php Class src
  Plain text file EndsWith.php Class src
  Plain text file EnsureLeft.php Class src
  Plain text file EnsureRight.php Class src
  Plain text file Hash.php Class Class source
  Plain text file HashCode.php Class src
  Plain text file HexColor.php Class Class source
  Plain text file HexDecimal.php Class Class source
  Plain text file IndexOf.php Class src
  Plain text file Ipv4.php Class Class source
  Plain text file Ipv6.php Class Class source
  Plain text file Isbn.php Class Class source
  Plain text file Join.php Class Class source
  Plain text file Json.php Class Class source
  Plain text file LastIndexOf.php Class src
  Plain text file Latitude.php Class Class source
  Plain text file Length.php Class src
  Plain text file Longitude.php Class Class source
  Plain text file Lowercase.php Class src
  Plain text file LowercaseCheck.php Class Class source
  Plain text file LowercaseFirst.php Class src
  Plain text file MultiByte.php Class Class source
  Plain text file Number.php Class src
  Plain text file Pad.php Class src
  Plain text file Random.php Class Class source
  Plain text file RemoveNonAscii.php Class src
  Plain text file RemoveWhitespace.php Class src
  Plain text file Repeat.php Class Class source
  Plain text file Replace.php Class src
  Plain text file ReplaceAccents.php Class src
  Plain text file Reverse.php Class src
  Plain text file RgbColor.php Class Class source
  Plain text file Semver.php Class Class source
  Plain text file SentenceCount.php Class Class source
  Plain text file Split.php Class src
  Plain text file StartsWith.php Class src
  Plain text file StringFindPosition.php Class src
  Plain text file StringFirstOccurrence.php Class src
  Plain text file StripPunctuation.php Class src
  Plain text file StripTags.php Class src
  Plain text file SubString.php Class src
  Plain text file SubStringCount.php Class src
  Plain text file SwapCase.php Class Class source
  Plain text file Transformer.php Class src
  Plain text file TransformerCaseInsensitive.php Class src
  Plain text file TransformerInterface.php Class src
  Plain text file Trim.php Class src
  Plain text file TrimLeft.php Class src
  Plain text file TrimRight.php Class src
  Plain text file Truncate.php Class src
  Plain text file TruncateMatch.php Class src
  Plain text file Uppercase.php Class src
  Plain text file UppercaseCheck.php Class Class source
  Plain text file UppercaseFirst.php Class src
  Plain text file UppercaseWords.php Class src
  Plain text file Url.php Class Class source
  Plain text file Width.php Class Class source
  Plain text file WordCount.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Plain text file AlphaNumericSpaceDashTest.php Class src
  Plain text file AlphaNumericSpaceTest.php Class src
  Plain text file AlphaNumericTest.php Class src
  Plain text file AlphaTest.php Class src
  Plain text file AsciiTest.php Class Class source
  Plain text file Base64Test.php Class Class source
  Plain text file BetweenTest.php Class Class source
  Plain text file BlankTest.php Class Class source
  Plain text file CamelizeTest.php Class src
  Plain text file CamelToSnakeTest.php Class Class source
  Plain text file CharsTest.php Class Class source
  Plain text file ChartAtTest.php Class Class source
  Plain text file ChopLeftTest.php Class Class source
  Plain text file ChopRightTest.php Class Class source
  Plain text file CollapseWhitespaceTest.php Class Class source
  Plain text file ConcatTest.php Class src
  Plain text file ContainsCountTest.php Class src
  Plain text file ContainsTest.php Class src
  Plain text file DasherizeTest.php Class src
  Plain text file DateTest.php Class src
  Plain text file DecimalTest.php Class src
  Plain text file DeleteTest.php Class Class source
  Plain text file EmailTest.php Class src
  Plain text file EmptyTest.php Class Class source
  Plain text file EndsWithTest.php Class src
  Plain text file EnsureLeftTest.php Class src
  Plain text file EnsureRightTest.php Class src
  Plain text file FirstTest.php Class Class source
  Plain text file HashCodeTest.php Class src
  Plain text file HashTest.php Class Class source
  Plain text file HasLowercaseTest.php Class Class source
  Plain text file HasUppercaseTest.php Class Class source
  Plain text file HexColorTest.php Class Class source
  Plain text file HexDecimalTest.php Class Class source
  Plain text file IndexOfTest.php Class src
  Plain text file Ipv4Test.php Class Class source
  Plain text file Ipv6Test.php Class Class source
  Plain text file IsbnTest.php Class Class source
  Plain text file JoinTest.php Class Class source
  Plain text file JsonTest.php Class Class source
  Plain text file LastIndexOfTest.php Class src
  Plain text file LastTest.php Class Class source
  Plain text file LatitudeTest.php Class Class source
  Plain text file LengthTest.php Class src
  Plain text file LineCountTest.php Class Class source
  Plain text file LongitudeTest.php Class Class source
  Plain text file LowercaseFirstTest.php Class src
  Plain text file LowercaseTest.php Class src
  Plain text file MultiByteTest.php Class Class source
  Plain text file NumberTest.php Class src
  Plain text file PadTest.php Class src
  Plain text file RandomTest.php Class Class source
  Plain text file RemoveNonAsciiTest.php Class src
  Plain text file RemoveWhitespaceTest.php Class src
  Plain text file RepeatTest.php Class Class source
  Plain text file ReplaceAccentsTest.php Class src
  Plain text file ReplaceTest.php Class src
  Plain text file ReverseTest.php Class src
  Plain text file RgbColorTest.php Class Class source
  Plain text file SemverTest.php Class Class source
  Plain text file SentenceCountTest.php Class Class source
  Plain text file SplitTest.php Class src
  Plain text file StartsWithTest.php Class src
  Plain text file StringizerTest.php Class src
  Plain text file StripPunctuationTest.php Class src
  Plain text file StripTagsTest.php Class src
  Plain text file SubStringTest.php Class src
  Plain text file SwapTest.php Class Class source
  Plain text file ToBooleanTest.php Class Class source
  Plain text file TransformerTest.php Class src
  Plain text file TrimLeftTest.php Class src
  Plain text file TrimRightTest.php Class src
  Plain text file TrimTest.php Class src
  Plain text file TruncateMatchTest.php Class src
  Plain text file TruncateTest.php Class src
  Plain text file UppercaseFirstTest.php Class src
  Plain text file UppercaseTest.php Class src
  Plain text file UppercaseWordTest.php Class src
  Plain text file UrlTest.php Class Class source
  Plain text file WidthTest.php Class src
  Plain text file WordCountTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:306
This week:6
All time:7,317
This week:135Up
User Ratings User Comments (1)
 All time
Utility:100%StarStarStarStarStarStar
Consistency:92%StarStarStarStarStar
Documentation:85%StarStarStarStarStar
Examples:-
Tests:-
Videos:-
Overall:67%StarStarStarStar
Rank:598
 
Proficiate.
6 years ago (Ian Onvlee)
65%StarStarStarStar
 
For more information send a message to info at phpclasses dot org.