soldatov / helpers
Helpers for string, array, objects, etc.
Installs: 1 101
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^7.3 || ^8.0
- ext-json: *
- ext-mbstring: *
- soldatov/gettype: ^1.0
Requires (Dev)
- phpunit/phpunit: ^9
README
Helpers that extend the standard functionality of the PHP.
StringHelper
StringHelper::parseToBool
Helps to recognize a boolean value.
use Soldatov\Helpers\StringHelper; var_dump(StringHelper::parseToBool('да')); // bool(true) var_dump(StringHelper::parseToBool('Yes')); // bool(true) var_dump(StringHelper::parseToBool(' yes')); // bool(true) var_dump(StringHelper::parseToBool('YES ')); // bool(true) var_dump(StringHelper::parseToBool('Y')); // bool(true) var_dump(StringHelper::parseToBool('y')); // bool(true) var_dump(StringHelper::parseToBool('t')); // bool(true) var_dump(StringHelper::parseToBool('1')); // bool(true) var_dump(StringHelper::parseToBool(1)); // bool(true) var_dump(StringHelper::parseToBool(true)); // bool(true) /* etc. */ var_dump(StringHelper::parseToBool('нет')); // bool(false) var_dump(StringHelper::parseToBool('no')); // bool(false) var_dump(StringHelper::parseToBool('n')); // bool(false) var_dump(StringHelper::parseToBool('false')); // bool(false) var_dump(StringHelper::parseToBool('none')); // bool(false) var_dump(StringHelper::parseToBool('0')); // bool(false) var_dump(StringHelper::parseToBool(0)); // bool(false) var_dump(StringHelper::parseToBool(false)); // bool(false) /* etc. */
StringHelper::parseJson
use Soldatov\Helpers\StringHelper; StringHelper::parseJson('asd'); // Fatal error: Uncaught JsonException: Syntax error in ...
use Soldatov\Helpers\StringHelper; var_export(StringHelper::parseJson('{"a": 123}')); // array ('a' => 123,) var_export(StringHelper::parseJson(' {"a": 123} ')); // array ('a' => 123,)
StringHelper::oneSpace
Removes extra spaces from a string.
use Soldatov\Helpers\StringHelper; var_export(StringHelper::oneSpace('One two 3 ')); // 'One two 3'
StringHelper::slicer
Splits a string by words into substrings that are no more than a certain length. Supports UTF-8.
use Soldatov\Helpers\StringHelper; var_export(StringHelper::slicer('One two One three', 10)); // array (0 => 'One two', 1 => 'One three')
VarHelper
VarHelper::checkVarType
Checks if a variable is of a specific type.
use Soldatov\GetType\Types; use Soldatov\Helpers\VarHelper; $var = 'test'; VarHelper::checkVarType($var, [Types::TYPE_STRING]); // ok VarHelper::checkVarType($var, [Types::TYPE_INTEGER, Types::TYPE_FLOAT]); // BadVarTypeException