Download the PHP package repat/php-helper without Composer

On this page you can find all versions of the php package repat/php-helper. 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-helper

php-helper

Latest Version on Packagist Total Downloads

php-helper is a package full of helper functions I found useful when developing applications in PHP. All functions are wrapped with a functions_exists() in case of conflicts.

⚠️ Some of these functions used to be in repat/laravel-helper, which now has this package as a dependency.

Also have a look at

Ideas what should go in here? Write a pull request or email!

Installation

$ composer require repat/php-helper

Documentation

Array

array_equal($arr1, $arr2)

Determines if 2 arrays have the same items, independent of order.

array_key2value($array)

Returns an array where key == value. Syntactic sugar for array_combine($array, $array);

array_delete_value($array, $value)

Deletes all elements from $array that have value $value. Essentially syntactic sugar for array_diff().

contains_duplicates($array)

Checks if there are duplicates in given array.

array_change_keys($array, $keys)

Changes the keys recursively for an associative array. The second parameter is an array with the old key (of $array) as the key and the new key as the value.

array_key_replace($array, $oldKey, $newKey)

Similar to array_change_keys() but it only works for one-dimensional arrays.

array_avg($array)

Calculates average (sum/amount) of values. Returns null if array is empty.

Date

days_in_month($month = null, $year = null)

Returns amount of days in given month or year. Defaults to current month and year.

days_this_month()

Returns amount of days of the current month.

days_next_month()

Returns amount of days of the next month.

days_this_year()

Returns amount of days of the current year.

days_left_in_month()

Returns amount of days left in current month.

days_left_in_year()

Returns amount of days left in current year.

timezone_list()

Returns a list of all timezones.

tomorrow()

Similar to today() or now(), this function returns a Carbon instance for tomorrow.

yesterday()

Similar to today() or now(), this function returns a Carbon instance for yesterday.

seconds2minutes($seconds)

Returns i:s string with 60+ minutes instead of showing the hours as well.

diff_in_days($start, $end)

Uses Carbons diffInDays() and parse() methods to return the difference in days.

Object

object2array($object)

Array representation of an object, e.g. an Eloquent Model.

filepath2fqcn($filepath, $prefix = '')

Will turn a filepath into a Fully Qualified Class Name.

Misc

toggle($switch)

If given true, returns false and vice-versa.

generate_password($size = 15)

Returns a random password. Syntactic sugar for str_random().

auto_cast($value)

Returns the value with the right type so e.g. you can compare type safe with ===.

human_filesize($size)

Returns a human readable form for given bytes. Goes up to Yottabyte.

permutations($array)

Returns a generator with all possible permutations of given array values.

Based on eddiewoulds port port of python code.

zenith($type)

Wrapper around magic numbers for the Zenith. The types can be:

operating_system()

Returns on of the following constants (also see under constants):

wikipedia($lemma, $lang = 'en', $return = '')

Link URL to wikipedia for a certain language

function_location($functionName)

Uses Reflection to return the location where the function was defined or null if function doesn't exist. Note that PHPs internal functions return a an empty string.

Networking

scrub_url($url)

Removes the protocol, www and trailing slashes from a URL. You can then e.g. test HTTP vs. HTTPS connections.

http_status_code($url, $follow = true, $userAgent = null)

Returns just the status code by sending an empty request with curl. By default, it follows redirect so it will only return the last status code and not e.g. 301 Redirects. Disable following by setting the second parameter to false. Some sites require a User-Agent and then return another status code. A string can be passed to $userAgent. Requires ext-curl.

parse_signed_request($request, $clientSecret, $algo)

Parses a HMAC signed request. Copied from Data Deletion Request Callback - Facebook for Developers. $algo defaults to sha256.

domain_slug($domain)

Validates a domain and creates a slug. Does not work for subdomains, see sluggify_domain() instead. Returns null on a parsing error.

gethostbyname6($domain)

Returns a IPv6 address for given domain by using the DNS AAAA records. If none is found, the input domain is returned, much like gethostbyname() is doing for IPv4.

is_public_ip($ip)

Returns if given IP is a public IPv4 or IPv6 address (vs. private or reserved)

final_redirect_target($url)

Follows all 301/302 redirects and returns the URL at the end of the chain, or null.

String

str_icontains($haystack, $needle)

Similar to Str::contains() but case insensitive.

to_ascii($string)

Removes all non ASCII characters and returns the rest.

hyphen2_($string)

Replaces all hyphen ("-") characters with underscore ("_")

_2hypen($string)

Replaces all underscore ("_") characters with hyphen ("-")

str_replace_once($search, $replace, $string)

Same signature as str_replace(), but as name suggests, replaces only the first occurrence of $search.

title_case_wo_underscore($string)

Title Case but without underscores.

lorem_ipsum()

Returns an example of the Lorem Ipsum placeholder text.

sluggify_domain($domain)

Returns a slug version of the domain by exchanging full stops with underscores. str_slug() does not work with subdomains, as it removes full stops completely.

str_remove($string, $remove)

Removes given string(s), numbers or array of strings. Syntactic sugar for str_replace($remove, '', $string).

str_bytes($string)

Returns the amount of bytes in a string.

regex_list($array)

Creates a string with regex for an OR separated list.

base64_url_decode($url)

Decodes a base64-encoded URL. Copied from Data Deletion Request Callback - Facebook for Developers

str_right($string, $until)

Syntactic sugar for str_after.

str_left($string, $before)

Syntactic sugar for str_before.

normalize_nl($string)

Normalizes all new lines characters (\r, \n, \r\n) to the UNIX newline \n.

str_count_upper($string)

Counts upper case characters in a string. See also str_count_lower().

str_count_lower($string)

Counts lower case characters in a string. See also str_count_upper().

str_insert_bindings($sql, $bindings)

Inserts bindings for ? characters in the SQL string. See also insert_bindings() of repat/laravel-helper.

contains_uppercase($string)

If the given string contains at least one uppercase ASCII character.

contains_lowercase($string)

If the given string contains at least one lowercase ASCII character.

contains_numbers($string)

If the given string (or number) contains at least one number.

country_name($iso, $locale)

Converts ISO Code 3166-1 alpha-2 $iso code into the full country name. Basically syntactic sugar for locale_get_display_region(). Optionally accepts $locale to print the country name in a given language. XK will give you Kosovo.

Wordpress

These functions were pulled in from the Open Source Content Management System Wordpress, released under the GPL 2 (or later).

remove_accents($string)

Removes special characters and replaces them with their ASCII counterparts

Optional Packages

Optional packages suggested by this are required for these functions to work.

markdown2html($markdown)

Uses league/commonmark to transform Markdown into HTML.

domain($url, $publicSuffixList)

Uses jeremykendall/php-domain-parser to return the domain only from a URL, removing protocol, subdomain (including www) and path. For that the package needs a public suffix list, which can be found at publicsuffix.org.

HTML

linkify($string, $protocols = ['http', 'https', 'mail'], $attributes)

Returns the string with all URLs for given protocols made into links. Optionally, attributes for the a tag can be passed.

embedded_video_url($url)

Returns the embedded version of a given YouTube or Vimeo URL.

ul_li_unpack($array, $separator)

Unpacks an associated array into an unordered list. Default separator is :.

contrast_color($bgColor)

Uses the Luminosity Contrast algorithm to determine if white or black would be the best contrast color for a given hex background color.

Source: tomloprod on stackoverflow

Flags

emoji_flag($iso)

Returns the emoji flag for a ISO-3166 alpha-2 code, such as nz for New Zealand or py for Paraguay. Lowercase / Uppercase doesn't play a role. Will return a waving black flag for non existing country code (or rather, Unicode doesn't have a flag for it) or null. XK will give you the flag of Kosovo.

Constants

Contributors

License

Version

Contact

repat

Flattr this git repo


All versions of php-helper with dependencies

PHP Build Version
Package Version
Requires ext-curl Version *
nesbot/carbon Version ^1.26.3 || ^2.0
php Version >=7.2
repat/date-constants Version *
repat/http-constants Version *
stevegrunwell/time-constants Version *
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 repat/php-helper contains the following files

Loading the files please wait ....