Download the PHP package clausnz/php-helpers without Composer
On this page you can find all versions of the php package clausnz/php-helpers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package php-helpers
About
The library clausnz/php-helpers
is a collection of 45 useful php helper functions (PHP 5.6, 7.*)
.
After installation with composer
, the global functions are accessable from everywhere in your code:
Installation
Example
If a function with the same name already exists in the list of your project's defined functions ( built-in and user-defined ), it will simply not be registered in your environment. Therefore, no conflicts with existing functions will appear.
Nevertheless, every function is still accessable it in a static way with the proper use-statement:
Example
CREDITS
This library makes use of the following brilliant and well known libraries:
- https://github.com/serbanghita/Mobile-Detect
- https://github.com/JayBizzle/Crawler-Detect
- https://github.com/mustangostang/spyc
Tests
All functions are tested against a number of unit tests and PHP Versions.
Install
Install the latest clausnz/php-helper
library with composer:
Also make sure to require your composer autoload file:
After installation, the new global PHP functions are available everywhere in your code. To access the ( almost identical ) static functions in the helper classes, add the proper use statement to your file:
Example
Available PHP Functions
Table of Contents
- Device
- is_mobile
- is_smartphone
- is_tablet
- is_desktop
- is_robot
- is_ios
- is_android
- is_iphone
- is_samsung
- Array
- array_get
- array_set
- array_first
- array_last
- to_array
- to_object
- is_assoc
- String
- str_before
- str_after
- str_after_last
- str_between
- str_insert
- str_limit
- str_limit_words
- str_contains
- str_icontains
- str_starts_with
- str_istarts_with
- str_ends_with
- str_iends_with
- Utils
- ip
- is_email
- dump
- dd
- crypt_password
- is_password
- Yml
- to_yml
- to_yml_file
- yml_parse
- yml_parse_file
- is_yml
- is_yml_file
- yml_get
- yml_get_file
- yml_set
- yml_set_file
API Documentation
Table of Contents
- Arr
- isAssoc
- toObject
- dump
- first
- last
- get
- set
- Dev
- isSmartphone
- isMobile
- mobileDetect
- isTablet
- isDesktop
- isRobot
- crawlerDetect
- isAndroid
- isIphone
- isSamsung
- isIOS
- Str
- insert
- between
- after
- before
- limitWords
- limit
- contains
- containsIgnoreCase
- startsWith
- startsWithIgnoreCase
- endsWith
- endsWithIgnoreCase
- afterLast
- Util
- isEmail
- ip
- cryptPassword
- isPassword
- dd
- dump
- Yml
- isValidFile
- isValid
- parse
- get
- getFile
- parseFile
- setFile
- dumpFile
- dump
- set
Arr
Helper class that provides easy access to useful php array functions.
Class Arr
- Full name: \CNZ\Helpers\Arr
isAssoc
Detects if the given value is an associative array.
is_assoc
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$array |
array | Any type of array. |
Return Value:
True if the array is associative, false otherwise.
toObject
Converts an array to an object.
to_object
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$array |
array | The array to be converted. |
Return Value:
A std object representation of the converted array.
dump
Converts a string or an object to an array.
to_array
Related global function (description see above).
( jump back )
Example 1 (string)
Example 2 (object)
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$var |
string|object | String or object. |
Return Value:
An array representation of the converted string or object. Returns null on error.
first
Returns the first element of an array.
array_first
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$array |
array | The concerned array. |
Return Value:
The value of the first element, without key. Mixed type.
last
Returns the last element of an array.
array_last
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$array |
array | The concerned array. |
Return Value:
The value of the last element, without key. Mixed type.
get
Gets a value in an array by dot notation for the keys.
array_get
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$key |
string | The key by dot notation. |
$array |
array | The array to search in. |
Return Value:
The searched value, null otherwise.
set
Sets a value in an array using the dot notation.
array_set
Related global function (description see above).
( jump back )
Example 1
Example 2
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$key |
string | The key to set using dot notation. |
$value |
mixed | The value to set on the specified key. |
$array |
array | The concerned array. |
Return Value:
True if the new value was successfully set, false otherwise.
Dev
Helper class that provides easy access to useful php functions in conjunction with the user agent.
Class Dev
- Full name: \CNZ\Helpers\Dev
isSmartphone
Determes if the current device is a smartphone.
is_smartphone
Related global function (description see above).
( jump back )
Example
- This method is static.
Return Value:
True if current visitor uses a smartphone, false otherwise.
isMobile
Detects if the current visitor uses a mobile device (Smartphone/Tablet/Handheld).
is_mobile
Related global function (description see above).
( jump back )
Example
- This method is static.
Return Value:
True if current visitor uses a mobile device, false otherwise.
mobileDetect
Get a singleton MobileDetect object to call every method it provides.
Public access for use of outside this class. Mobile_Detect doku: https://github.com/serbanghita/Mobile-Detect
This method has no related global function!
( jump back )
Example
- This method is static.
Return Value:
A singleton MobileDetect object to call every method it provides.
isTablet
Determes if the current visitor uses a tablet device.
is_tablet
Related global function (description see above).
( jump back )
Example
- This method is static.
Return Value:
True if current visitor uses a tablet device, false otherwise.
isDesktop
Determes if the current visitor uses a desktop computer.
is_desktop
Related global function (description see above).
( jump back )
Example
- This method is static.
Return Value:
True if current visitor uses a desktop computer, false otherwise.
isRobot
Determes if the current visitor is a search engine/bot/crawler/spider.
is_robot
Related global function (description see above).
( jump back )
Example
- This method is static.
Return Value:
True if the current visitor is a search engine/bot/crawler/spider, false otherwise.
crawlerDetect
Get a singleton CrawlerDetect object to call every method it provides.
Public access for use of outside this class. Crawler-Detect doku: https://github.com/JayBizzle/Crawler-Detect
This method has no related global function!
( jump back )
Example
- This method is static.
isAndroid
Determes if the current device is running an Android operating system.
is_android
Related global function (description see above).
( jump back )
Example
- This method is static.
Return Value:
True if current visitor uses an Android based device, false otherwise.
isIphone
Determes if the current device is an iPhone.
is_iphone
Related global function (description see above).
( jump back )
Example
- This method is static.
Return Value:
True if current visitor uses an iPhone, false otherwise.
isSamsung
Determes if the current device is from Samsung.
is_samsung
Related global function (description see above).
( jump back )
Example
- This method is static.
Return Value:
True if current visitor uses a Samsung device, false otherwise.
isIOS
Determes if the current device is running an iOS operating system.
is_ios
Related global function (description see above).
( jump back )
Example
- This method is static.
Return Value:
True if current visitor uses an iOS device, false otherwise.
Str
Helper class that provides easy access to useful php string functions.
Class Str
- Full name: \CNZ\Helpers\Str
insert
Inserts one or more strings into another string on a defined position.
str_insert
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$keyValue |
array | An associative array with key => value pairs. |
$string |
string | The text with the strings to be replaced. |
Return Value:
The replaced string.
between
Return the content in a string between a left and right element.
str_between
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$left |
string | The left element of the string to search. |
$right |
string | The right element of the string to search. |
$string |
string | The string to search in. |
Return Value:
A result array with all matches of the search.
after
Return the part of a string after a given value.
str_after
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$search |
string | The string to search for. |
$string |
string | The string to search in. |
Return Value:
The found string after the search string. Whitespaces at beginning will be removed.
before
Get the part of a string before a given value.
str_before
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$search |
string | The string to search for. |
$string |
string | The string to search in. |
Return Value:
The found string before the search string. Whitespaces at end will be removed.
limitWords
Limit the number of words in a string. Put value of $end to the string end.
str_limit_words
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$string |
string | The string to limit the words. |
$limit |
integer | The number of words to limit. Defaults to 10. |
$end |
string | The string to end the cut string. Defaults to '...' |
Return Value:
The limited string with $end at the end.
limit
Limit the number of characters in a string. Put value of $end to the string end.
str_limit
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$string |
string | The string to limit the characters. |
$limit |
integer | The number of characters to limit. Defaults to 100. |
$end |
string | The string to end the cut string. Defaults to '...' |
Return Value:
The limited string with $end at the end.
contains
Tests if a string contains a given element
str_contains
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$needle |
string|array | A string or an array of strings. |
$haystack |
string | The string to search in. |
Return Value:
True if $needle is found, false otherwise.
containsIgnoreCase
Tests if a string contains a given element. Ignore case sensitivity.
str_icontains
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$needle |
string|array | A string or an array of strings. |
$haystack |
string | The string to search in. |
Return Value:
True if $needle is found, false otherwise.
startsWith
Determine if a given string starts with a given substring.
str_starts_with
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$needle |
string|array | The string or array of strings to search for. |
$haystack |
string | The string to search in. |
Return Value:
True if $needle was found, false otherwise.
startsWithIgnoreCase
Determine if a given string starts with a given substring. Ignore case sensitivity.
str_istarts_with
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$needle |
string|array | The string or array of strings to search for. |
$haystack |
string | The string to search in. |
Return Value:
True if $needle was found, false otherwise.
endsWith
Determine if a given string ends with a given substring.
str_ends_with
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$needle |
string|array | The string or array of strings to search for. |
$haystack |
string | The string to search in. |
Return Value:
True if $needle was found, false otherwise.
endsWithIgnoreCase
Determine if a given string ends with a given substring.
str_iends_with
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$needle |
string|array | The string or array of strings to search for. |
$haystack |
string | The string to search in. |
Return Value:
True if $needle was found, false otherwise.
afterLast
Return the part of a string after the last occurrence of a given search value.
str_after_last
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$search |
string | The string to search for. |
$string |
string | The string to search in. |
Return Value:
The found string after the last occurrence of the search string. Whitespaces at beginning will be removed.
Util
Helper class that provides easy access to useful common php functions.
Class Util
- Full name: \CNZ\Helpers\Util
isEmail
Validate a given email address.
is_email
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$email |
string | The email address to test. |
Return Value:
True if given string is a valid email address, false otherwise.
ip
Get the current ip address of the user.
user_ip
Related global function (description see above).
( jump back )
Example
- This method is static.
Return Value:
The detected ip address, null if the ip was not detected.
cryptPassword
Creates a secure hash from a given password. Uses the CRYPT_BLOWFISH algorithm.
Note: 255 characters for database column recommended!
crypt_password
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$password |
string | The password to crypt. |
Return Value:
The crypted password.
isPassword
Verifies that a password matches a crypted password (CRYPT_BLOWFISH algorithm).
is_password
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$password |
string | The password to test. |
$cryptedPassword |
string | The crypted password (e.g. stored in the database). |
dd
Dumps the content of the given variable and exits the script.
dd
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$var |
mixed | The var to dump. |
dump
Dumps the content of the given variable. Script does NOT stop after call.
dump
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$var |
mixed | The var to dump. |
Yml
Helper class that provides easy access to useful php yml functions.
Class Yml
- Full name: \CNZ\Helpers\Yml
isValidFile
Validates if a given file contains yaml syntax.
is_yml_file
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$file |
string | The file to test for yaml syntax. |
Return Value:
True if the file contains yaml syntax, false otherwise.
isValid
Tests if the syntax of a given string is yaml.
is_yml
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$string |
string | The string to test for yaml syntax. |
Return Value:
True if the string is yaml, false otherwise.
parse
Transforms a given yaml string into an array.
yml_parse
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$yml |
string | The yaml string to parse. |
Return Value:
The transformed array, null on error.
get
Gets a value in a yaml string using the dot notation.
yml_get
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$key |
string | The key to search using dot notation (e.g. 'foo.bar.baz'). |
$yml |
string | The yml string to search in. |
Return Value:
The found value, null otherwise.
getFile
Gets a value in a yaml file using the dot notation.
yml_get_file
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$key |
string | The key to search using dot notation (e.g. 'foo.bar.baz'). |
$ymlfile |
string | The ymlfile to search in. |
Return Value:
The found value, null otherwise.
parseFile
Loads the content of a yamlfile into an array.
yml_parse_file
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$ymlfile |
string | The path of the file to read from. |
Return Value:
The parsed array.
setFile
Sets a value in a yamlfile using the dot notation. Note: all comments in the file will be removed!
yml_set_file
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$key |
string | The string to search with dot notation |
$value |
mixed | The value to set on the specified key. |
$ymlfile |
string | The ymlfile to set the value in. |
Return Value:
True if value was successfully set in yamlfile, false otherwise.
dumpFile
Transformes a given array to yaml syntax and puts its content into a given file. Note: if the file exists, it will be overwritten!
to_yml_file
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$var |
array|object | The array or object to transform. |
$filename |
string | The path to the file to write the yaml string into. Note: if the file already exists, it will be overwritten! |
$indent |
integer | The indent of the converted yaml. Defaults to 2. |
$wordwrap |
integer | After the given number a string will be wraped. Default to 0 (no wordwrap). |
$openingDashes |
boolean | True if the yaml string should start with opening dashes. Defaults to false. |
Return Value:
True on success, false otherwise.
dump
Transformes a given array or object to a yaml string.
to_yml
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$var |
array|object | The array or object to transform. |
$indent |
integer | The indent of the converted yaml. Defaults to 2. |
$wordwrap |
integer | After the given number a string will be wraped. Default to 0 (no wordwrap). |
$openingDashes |
boolean | True if the yaml string should start with opening dashes. Defaults to false. |
Return Value:
The converted yaml string. On errors, null is returned.
set
Sets a value in a yaml string using the dot notation.
yml_set
Related global function (description see above).
( jump back )
Example
- This method is static. Parameters:
Parameter | Type | Description |
---|---|---|
$key |
string | The string to search with dot notation |
$value |
mixed | The value to set on the specified key. |
$yml |
string | The yml string to search in. Note: all comments in the string will be removed! |
Return Value:
True if value was successfully set, false otherwise.
This document was automatically generated from source code comments on 2018-01-22 using phpDocumentor and cvuorinen/phpdoc-markdown-public
All versions of php-helpers with dependencies
mobiledetect/mobiledetectlib Version ^2.8
jaybizzle/crawler-detect Version ^1.2
mustangostang/spyc Version ^0.6