2017 © Pedro Peláez
 

library smartstring

A class to manipulate a string with a better syntax.

image

pataar/smartstring

A class to manipulate a string with a better syntax.

  • Wednesday, January 31, 2018
  • by pataar
  • Repository
  • 2 Watchers
  • 4 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

SmartString

Installation

Using Composer:, (*1)

composer require pataar/smartstring

Usage

Creating a SmartString object

Either do, (*2)

\Pataar\SmartString::create("Sample String");

Or, (*3)

new \Pataar\SmartString("Sample String");
Using a SmartString object

After creating your SmartString, you can use several chainable methods to manipulate the string., (*4)

Some examples:, (*5)

$sampletext = "Sample String";

echo \Pataar\SmartString::create($sampletext)->remove("String")->trim();
//which would echo "Sample"

echo \Pataar\SmartString::create($sampletext)->prefix("A new ")->normalize();
//which would echo "a-new-sample-string"

echo \Pataar\SmartString::create($sampletext)->toMd5WithSalt("Salting is good");
//which would echo "560fbd0056c4354c5dd0de0580c8c523"

echo \Pataar\SmartString::create($sampletext)->remove("String")->trim()->toLower()->prefix("String ");
//which would echo "String sample"

Functions

toUpper()

Creates an uppercase version of the string., (*6)

$smartString->toUpper();

toLower()

Creates an lowercase version of the string., (*7)

$smartString->toLower();

Trim()

Trims the string. So removes any trailing whitespaces and spaces., (*8)

$smartString->trim();

printme()

Prints the string., (*9)

$smartString->printme();

indexOf($input)

Returns the index of a certain $input string., (*10)

$smartString->indexOf($input);

substring($start, $length)

Creates a substring of an existing string., (*11)

$smartString->substring($start, $length);

toMd5()

Creates an MD5 hash of the string., (*12)

$smartString->toMd5();

toMd5WithSalt($salt)

Creates an salted MD5 hash of the string. Using both a prefix and suffix containing the given $salt., (*13)

$smartString->toMd5WithSalt($salt);

encodeB64() || decodeB64()

Encodes or decodes a B64 string., (*14)

$smartString->encodeB64();
$smartString->decodeB64();

charAt($index)

Tells you on which index a certain character is placed., (*15)

$smartString->charAt($index);

equals($string)

Returns when the $string matches the $smartString., (*16)

$smartString->equals($string);

prefix($prefix)

Adds a $prefix to the string., (*17)

$smartString->prefix($prefix);

suffix($suffix)

Adds a $suffix to the string., (*18)

$smartString->suffix($suffix);

concat($string)

Concats a string., (*19)

$smartString->concat($string);

replace($search, $replacement)

Replace a string with an other string., (*20)

$smartString->replace($search, $replacement);

replacePattern($pattern, $replacement)

Replaces a pattern., (*21)

$smartString->replacePattern($pattern, $replacement);

remove($string)

Remove a string, (*22)

$smartString->remove($string);

length()

Returns the length of the string., (*23)

$smartString->length();

normalize()

Normalizes the string. Making it URL/slug compatible., (*24)

$smartString->normalize();

The Versions

31/01 2018

dev-master

9999999-dev

A class to manipulate a string with a better syntax.

  Sources   Download

MIT

by Avatar pataar

19/06 2016

1.0.1

1.0.1.0

A class to manipulate a string with a better syntax.

  Sources   Download

MIT

by Avatar pataar

18/06 2016

1.0.0

1.0.0.0

A class to manipulate a string with a better syntax.

  Sources   Download

MIT

by Avatar pataar