bitandblack / helpers
Useful methods for PHP you may like.
Fund package maintenance!
Buymeacoffee
Requires
- php: >=8.2
- ext-curl: *
- ext-dom: *
- ext-json: *
- ext-libxml: *
- ext-mbstring: *
Requires (Dev)
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^11.0
- rector/rector: ^1.0
- symplify/easy-coding-standard: ^12.0
README
Helpers
Useful methods you may like.
Installation
This library is available for the use with Composer. Add it to your project by running $ composer require bitandblack/helpers.
Use
All methods are defined static and can be used without the need of initializing an object. Also most of them are able to handle single input values as well as arrays.
There are useful methods to handle:
Arrays
ArrayHelper::usortMultiSorts multidimensional array by their values.ArrayHelper::uniqueArrayUniques an array be a given key.ArrayHelper::getIfIsArrayReturns the input if it's an array, otherwise false or a custom value.ArrayHelper::getArrayReturns the input as array.ArrayHelper::getValueIfKeyExistsReturns the value of an array based on it's key.ArrayHelper::recurseRuns a function on an input, no matter if it's a string or an array.
File System
FileSystemHelper::copyFolderCopies a whole folder with all of its contents, including subfolders.FileSystemHelper::deleteFolderDeletes a folder with all of its files.
Numbers
NumberHelper::convertNumberConverts a number into a given format.
Requests
RequestHelper::sortUploadFilesSort all uploaded images to a nice array.
Strings
SanitizeHelper::htmlEntitiesReturns the input converted by the htmlentities function.SanitizeHelper::htmlEntityDecodeReturns the input converted by the html_entity_decode function.SanitizeHelper::htmlSpecialCharsReturns the input converted by the htmlspecialchars function.StringHelper::stringToBooleanConverts the input to boolean if possible.StringHelper::stringToBooleanAdvancedConverts the input to boolean if possible and handles alsoyesandno.StringHelper::stringToIntConverts the input to int if possible.StringHelper::stringToFloatConverts the input to float if possible.StringHelper::stringToNumberConverts the input to int or float if possible.StringHelper::strReplaceMultiReplaces values in multidimensional arrays.StringHelper::booleanToStringConvertsnull, and the booleanstrueandfalseto words.StringHelper::mbUcFirstConverts the first character to uppercase.StringHelper::mbStrRevReverse a string.
URLs
URLHelper::getContentByURLReturns the content of a page using allow_url_fopen or curl.URLHelper::getScriptURLReturns the script url parameter.
XMLs
XMLHelper::hasGetOrProofs if an attribute exists and returns its content or returns the option parameter instead.XMLHelper::hasIsAttributeChecks if an XML element has an attribute with a given value.XMLHelper::loadHTMLLoads HTML safely and ignores errors.
Help
If you have any questions, feel free to contact us under hello@bitandblack.com.
Further information about Bit&Black can be found under www.bitandblack.com.