Wallogit.com
2017 © Pedro Peláez
A class to manipulate a string with a better syntax.
Using Composer:, (*1)
composer require pataar/smartstring
Either do, (*2)
\Pataar\SmartString::create("Sample String");
Or, (*3)
new \Pataar\SmartString("Sample String");
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"
Creates an uppercase version of the string., (*6)
$smartString->toUpper();
Creates an lowercase version of the string., (*7)
$smartString->toLower();
Trims the string. So removes any trailing whitespaces and spaces., (*8)
$smartString->trim();
Prints the string., (*9)
$smartString->printme();
Returns the index of a certain $input string., (*10)
$smartString->indexOf($input);
Creates a substring of an existing string., (*11)
$smartString->substring($start, $length);
Creates an MD5 hash of the string., (*12)
$smartString->toMd5();
Creates an salted MD5 hash of the string. Using both a prefix and suffix containing the given $salt., (*13)
$smartString->toMd5WithSalt($salt);
Encodes or decodes a B64 string., (*14)
$smartString->encodeB64(); $smartString->decodeB64();
Tells you on which index a certain character is placed., (*15)
$smartString->charAt($index);
Returns when the $string matches the $smartString., (*16)
$smartString->equals($string);
Adds a $prefix to the string., (*17)
$smartString->prefix($prefix);
Adds a $suffix to the string., (*18)
$smartString->suffix($suffix);
Concats a string., (*19)
$smartString->concat($string);
Replace a string with an other string., (*20)
$smartString->replace($search, $replacement);
Replaces a pattern., (*21)
$smartString->replacePattern($pattern, $replacement);
Remove a string, (*22)
$smartString->remove($string);
Returns the length of the string., (*23)
$smartString->length();
Normalizes the string. Making it URL/slug compatible., (*24)
$smartString->normalize();