Download the PHP package jstewmc/php-helpers without Composer

On this page you can find all versions of the php package jstewmc/php-helpers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-helpers

CircleCI codecov

PHP Helpers

Static classes to help with PHP strings, arrays, numbers, files, and boolean values.

Static helper classes are nothing new in PHP. In fact, most of these functions have probably been written dozens of times in better libraries than mine. However, I wrote (or copied these functions from the web with credit) when I worked on a project that required as few dependencies as possible, and I figured I would share them.

Installation

This library requires PHP 7.4+.

It is multi-platform, and we strive to make it run equally well on Windows, Linux, and OSX.

It should be installed via Composer. To do so, add the following line to the require section of your composer.json file, and run composer update:

Usage

Here are examples for the most commonly used functions.

(Please note, I've omitted the requisite use Jstewmc\PhpHelpers\{Arr, Boolean, Dir, Num, Str}; statements to keep the examples cleaner.)

Numbers (aka, "Num")

You can use val() method to evaluate integers, floats, fractions (e.g., "1/2"), mixed numbers (e.g., "1 1/2"), comma-separated values (e.g., "1,000"), and english-worded numbers (e.g., "two hundred and fifty-six") to their numeric equivalent:

You can use the *To() methods to round, ceil, or floor a number to the nearest multiple of another number:

You can use the bound() method to keep a number greater than or equal to a lower bound, less than or equal to an upper bound, or both:

You can use the normalize() method to index a number according to a maximum value:

You can use the isNumeric() method to test whether or not a value is a number, including fractions, mixed numbers, and english phrases:

You can use the isInt() method to test whether or not a number or string is an integer:

You can use the isId() method to test whether or not a number is a valid database identifier (i.e., a positive integer, optionally of the correct datatype size):

You can use the isZero() method to test whether or not a value is zero (in loosely-typed languages like PHP, zero can be many things):

You can use the almostEqual() method to test whether or not two floats are "equal" (because of the way floats are stored in memory, you shouldn't compare them directly using the == or === operators):

Strings (aka, "Str")

You can use rand() to generate a random string of a given length, optionally with specific latin character sets (allowed character sets are 'lower', 'upper', 'alpha' (a shortcut for 'lower' + 'upper'), number, or symbol):

You can use password() to generate a random string, optionally with the minimum number of characters that must be present from latin character sets:

You can use truncate() to neatly cut a string at or near the desired length (by default, the break character is the space character (' ') and the padding is an ellipsis ('...')):

You can use the *With() methods to determine whether or not a string starts or ends with a given substring:

You can use the strtocamelcase() method to convert a string to camel-case:

You can use the splitOnFirstAlpha() method to split a string on the first alphabetical character:

You can use the strtobytes() method to convert an .ini-style byte string (e.g., '1G') to a number:

You can use the isBool() method to determine whether or not a string is a "bool-ish" value:

Booleans

You can use the booltostr() method to convert a boolean value to a string:

You can use the val() method to evaluate a "bool-ish" value to its boolean equivalent (PHP's native boolval() method doesn't support "yes"/"no" or "on"/"off" strings):

Arrays (aka, "Arr")

You can use the filterByKeyPrefix() to filter an array by a string prefix:

You can use the filterByKey() method to filter an array by key using a custom function:

You can use the sortByField() method to sort an array of associative arrays in ascending or descending order:

You can use the sortByProperty() or sortByMethod() methods to sort an array of objects in ascending or descending order, using a property or method, respectively:

You can use the inArray() method to search for values in an array using wildcard notation (by default, the wildcard character is the asterisk character ("*")):

You can use the diff() method to determine the Levenshtein Distance, the number of single-element edits required to change one array into another) between two arrays:

You can use the permute() method to calculate an array's permutations (careful, the number of permutations grows as a factorial of the size of the original array):

You can use the isAssoc() method to determine whether or not an array is associative (i.e., has a string key):

You can use the isEmpty() method to determine whether or not a key exists in an array with a non-empty value:

You can use the keyStringReplace() method to replace substrings in array keys:

Directories (aka, "Dir")

You can use the copy() method to duplicate a non-empty directory (PHP's native copy() method will not work with non-empty directories):

You can use the remove() method to delete a non-empty directory (PHP's native rmdir() method will not work with non-empty directories):

You can use the abs2rel() method to convert an absolute path name to a relative one:

License

This library is released under the MIT License.

Contributing

Contributions are welcome!


All versions of php-helpers with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3 || ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jstewmc/php-helpers contains the following files

Loading the files please wait ....