Scriptlog Docs

Scriptlog Documentation

Code reference for the Scriptlog codebase

User Tools

Site Tools


scriptlog:lib:core:util

Util

Layer: Core · Source: lib/core/Util.php:21 (lines 21–2543)


class Util

Util.php

util.php is a library of helper functions for common tasks such as formatting bytes as a string or displaying a date in terms of how long ago it was in human readable terms (E.g. 4 minutes ago). The library is entirely contained within a single file and hosts no dependencies. The library is designed to avoid any possible conflicts.

Docblock Metadata

Tag Value
@author Brandon Wamboldt brandon.wamboldt@gmail.com

Inheritance

No parent, interface or trait. This is a root type.

Constants (18)

Visibility Name Value Line
- SECONDS_IN_A_MINUTE 60; 29
- SECONDS_IN_A_HOUR 3600; 37
- SECONDS_IN_AN_HOUR 3600; 38
- SECONDS_IN_A_DAY 86400; 46
- SECONDS_IN_A_WEEK 604800; 54
- SECONDS_IN_A_MONTH 2_592_000; 62
- SECONDS_IN_A_YEAR 31_536_000; 70
- HTTP_URL_REPLACE 1; 78
- HTTP_URL_JOIN_PATH 2; 79
- HTTP_URL_JOIN_QUERY 4; 80
- HTTP_URL_STRIP_USER 8; 81
- HTTP_URL_STRIP_PASS 16; 82
- HTTP_URL_STRIP_AUTH 32; 83
- HTTP_URL_STRIP_PORT 64; 84
- HTTP_URL_STRIP_PATH 128; 85
- HTTP_URL_STRIP_QUERY 256; 86
- HTTP_URL_STRIP_FRAGMENT 512; 87
- HTTP_URL_STRIP_ALL 1024; 88

Properties (8)

Visibility Type Name Default Line
public static static $icon_collapse 'iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAMAAADXT/YiAAAAGXRFWHRTb2… 96
public static static $icon_expand 'iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAMAAADXT/YiAAAAGXRFWHRTb2… 104
private static static $hasArray false 106
public static static $maps array( 'de' ⇒ array(/* German */ 'Ä' ⇒ 'Ae', 'Ö' ⇒ 'Oe',… 116
private static static $map array() 223
private static static $chars '''''' 230
private static static $regex '''''' 237
private static static $language '''''' 244

Methods (70)

Visibility Method Summary Line
private static initLanguageMap() Initializes the character map. 253
public static array_get() Access an array index, retrieving the value stored there if it 294
public static var_dump() Display a variable's contents using nice HTML formatting and will 308
public static var_dump_plain() Display a variable's contents using nice HTML formatting (Without 351
public static slugify() Converts any accent characters to their equivalent normal characters 516
public static seems_utf8() Checks to see if a string is utf8 encoded. 554
protected static seemsUtf8Regex() A non-Mbstring UTF-8 checker. 573
public static size_format() Nice formatting for computer sizes (Bytes). 601
public static maybe_serialize() Serialize data, if needed. 628
public static maybe_unserialize() Unserialize value only if it is serialized. 643
public static is_serialized() Check value to find if it was serialized. 695
public static fix_broken_serialization() Unserializes partially-corrupted arrays that occur sometimes. Addresses 735
public static is_https() Checks to see if the page is being server over SSL or not 750
public static add_query_arg() Add or remove query arguments to the URL. 763
public static remove_query_arg() Removes an item or list from the query string. 831
public static http_build_url() Build a URL. 858
public static str_to_bool() Converts many english words that equate to true or false to boolean. 983
public static starts_with() Check if a string starts with the given string. 1004
public static ends_with() Check if a string ends with the given string. 1016
public static str_contains() Check if a string contains another string. 1028
public static str_icontains() Check if a string contains another string. This version is case 1041
public static get_file_ext() Return the file extension of the given filename. 1052
public static rmdir() Removes a directory (and its contents) recursively. 1067
public static htmlentities() Convert entities, while preserving already-encoded entities. 1117
public static htmlspecialchars() Convert >, <, ', “ and & to html entities, but preserves entities that 1142
public static downcode() Transliterates characters to their ASCII equivalents. 1172
public static remove_accents() Converts all accent characters to ASCII characters. 1212
public static strip_space() Strip all witespaces from the given string. 1227
public static sanitize_string() Sanitize a string by performing the following operation : 1242
public static zero_pad() Pads a given string with zeroes on the left. 1259
public static human_time_diff() Converts a unix timestamp to a relative time string, such as “3 days ago” 1273
public static number_to_word() Converts a number into the text equivalent. For example, 456 becomes four 1330
protected static numberToWordConvertGroup() (undocumented) 1386
protected static numberToWordThreeDigits() (undocumented) 1418
protected static numberToWordTwoDigits() (undocumented) 1442
protected static numberToWordConvertDigit() string 1515
public static utf8_headers() Transmit UTF-8 content headers if the headers haven't already been sent. 1549
public static force_download() Transmit headers that force a browser to display the download file 1574
public static nocache_headers() Sets the headers to prevent caching for the different browsers. 1621
public static random_string() Generates a string of random characters. 1659
public static secure_random_string() Generate secure random string of given length 1721
public static match_string() Check if a given string matches a given pattern. 1747
public static validate_email() Validate an email address. 1771
public static get_gravatar() Return the URL to a user's gravatar. 1783
public static linkify() Turns all of the links in a string into HTML links. 1804
protected static linkifyRegex() Callback for the preg_replace in the linkify() method. 1831
protected static linkifyCallback() Callback for the preg_replace in the linkify() method. 1887
public static get_current_url() Return the current URL. 1901
public static get_client_ip() Returns the IP address of the client. 1964
public static safe_truncate() Truncate a string to a specified length without cutting a word off. 1990
public static limit_characters() Truncate the string to given length of charactes. 2015
public static limit_words() Truncate the string to given length of words. 2032
public static ordinal() Returns the ordinal version of a number (appends th, st, nd, rd). 2049
public static full_permissions() Returns the file permissions as a nice string, like -rw-r–r– or false 2067
public static array_first() Returns the first element in an array. 2132
public static array_last() Returns the last element in an array. 2143
public static array_first_key() Returns the first key in an array. 2154
public static array_last_key() Returns the last key in an array. 2167
public static array_flatten() Flatten a multi-dimensional array into a one dimensional array. 2185
public static array_pluck() Accepts an array, and returns an array of values from that array as 2214
public static array_search_deep() Searches for a given value in an array of arrays, objects and scalar 2256
public static array_map_deep() Returns an array containing all the elements of arr1 after applying 2304
public static array_clean() (undocumented) 2318
protected static mbInternalEncoding() Wrapper to prevent errors if the user doesn't have the mbstring 2330
public static set_writable() Set the writable bit on a file to the minimum value that allows the user 2349
public static set_readable() Set the readable bit on a file to the minimum value that allows the user 2401
public static set_executable() Set the executable bit on a file to the minimum value that allows the 2453
public static directory_size() Returns size of a given directory in bytes. 2503
public static get_user_directory() Returns a home directory of current user. 2519
public static directory_contents() Returns all paths inside a directory. 2534

initLanguageMap()

private static function initLanguageMap($language = &#039;&#039;)

lines 253–280 (28)

Initializes the character map.

Part of the URLify.php Project <https://github.com/jbroadway/urlify/>

Parameter Type Default Description
$language (untyped) '''''' none

Returns: (none declared)

array_get()

public static function array_get(&amp;$var, $default = null)

lines 294–297 (4)

Access an array index, retrieving the value stored there if it

exists or a default if it does not. This function allows you to concisely access an index which may or may not exist without raising a warning.

Parameter Type Default Description
$var (by reference) (untyped) required Array value to access
$default (untyped) null Default value to return if the key is not present in the array

Returns: (none declared) — mixed

var_dump()

public static function var_dump($var, $return = false, $expandLevel = 1)

lines 308–340 (33)

Display a variable's contents using nice HTML formatting and will

properly display the value of booleans as true or false

Parameter Type Default Description
$var (untyped) required The variable to dump
$return (untyped) false none
$expandLevel (untyped) 1 none

Returns: (none declared) — string

var_dump_plain()

public static function var_dump_plain($var, $expLevel, $depth = 0, $done = array())

lines 351–500 (150)

Display a variable's contents using nice HTML formatting (Without

the <pre> tag) and will properly display the values of variables like booleans and resources. Supports collapsable arrays and objects as well.

Parameter Type Default Description
$var (untyped) required The variable to dump
$expLevel (untyped) required none
$depth (untyped) 0 none
$done (untyped) array() none

Returns: (none declared) — string

slugify()

public static function slugify($string, $separator = &#039;-&#039;, $css_mode = false)

lines 516–541 (26)

Converts any accent characters to their equivalent normal characters

and converts any other non-alphanumeric characters to dashes, then converts any sequence of two or more dashes to a single dash. This function generates slugs safe for use as URLs, and if you pass true as the second parameter, it will create strings safe for use as CSS classes or IDs.

Parameter Type Default Description
$string (untyped) required A string to convert to a slug
$separator (untyped) '-' The string to separate words with
$css_mode (untyped) false Whether or not to generate strings safe for CSS classes/IDs (Default to false)

Returns: (none declared) — string

seems_utf8()

public static function seems_utf8($string)

lines 554–565 (12)

Checks to see if a string is utf8 encoded.

NOTE: This function checks for 5-Byte sequences, UTF8

    has Bytes Sequences with a maximum length of 4.

Written by Tony Ferrara <http://blog.ircmaxwell.com>

Parameter Type Default Description
$string (untyped) required The string to be checked

Returns: (none declared) — boolean

seemsUtf8Regex()

protected static function seemsUtf8Regex($string)

lines 573–592 (20)

A non-Mbstring UTF-8 checker.

Parameter Type Default Description
$string (untyped) required none

Returns: (none declared) — bool

size_format()

public static function size_format($bytes, $decimals = 0)

lines 601–620 (20)

Nice formatting for computer sizes (Bytes).

Parameter Type Default Description
$bytes (untyped) required The number in bytes to format
$decimals (untyped) 0 The number of decimal points to include

Returns: (none declared) — string

maybe_serialize()

public static function maybe_serialize($data)

lines 628–635 (8)

Serialize data, if needed.

Parameter Type Default Description
$data (untyped) required Data that might need to be serialized

Returns: (none declared) — mixed

maybe_unserialize()

public static function maybe_unserialize($data)

lines 643–684 (42)

Unserialize value only if it is serialized.

Parameter Type Default Description
$data (untyped) required A variable that may or may not be serialized

Returns: (none declared) — mixed

is_serialized()

public static function is_serialized($data)

lines 695–721 (27)

Check value to find if it was serialized.

If $data is not an string, then returned value will always be false. Serialized data is always a string.

Parameter Type Default Description
$data (untyped) required Value to check to see if was serialized

Returns: (none declared) — boolean

fix_broken_serialization()

public static function fix_broken_serialization($brokenSerializedData)

lines 735–743 (9)

Unserializes partially-corrupted arrays that occur sometimes. Addresses

specifically the `unserialize(): Error at offset xxx of yyy bytes` error.

NOTE: This error can *frequently* occur with mismatched character sets and higher-than-ASCII characters.

Contributed by Theodore R. Smith of PHP Experts, Inc. <http://www.phpexperts.pro/>

Parameter Type Default Description
$brokenSerializedData (untyped) required none

Returns: (none declared) — string

is_https()

public static function is_https()

lines 750–753 (4)

Checks to see if the page is being server over SSL or not

Takes no parameters.

Returns: (none declared) — boolean

add_query_arg()

public static function add_query_arg($newKey, $newValue = null, $uri = null)

lines 763–822 (60)

Add or remove query arguments to the URL.

Parameter Type Default Description
$newKey (untyped) required Either newkey or an associative array
$newValue (untyped) null Either newvalue or oldquery or uri
$uri (untyped) null URI or URL to append the queru/queries to.

Returns: (none declared) — string

remove_query_arg()

public static function remove_query_arg($keys, $uri = null)

lines 831–838 (8)

Removes an item or list from the query string.

Parameter Type Default Description
$keys (untyped) required Query key or keys to remove.
$uri (untyped) null When false uses the $_SERVER value

Returns: (none declared) — string

http_build_url()

public static function http_build_url($url, $parts = array(), $flags = self::HTTP_URL_REPLACE, &amp;$new_url = array())

lines 858–971 (114)

Build a URL.

The parts of the second URL will be merged into the first according to the flags argument.

Parameter Type Default Description
$url (untyped) required (part(s) of) an URL in form of a string or associative array like parse_url() returns
$parts (untyped) array() same as the first argument
$flags (untyped) self::HTTP_URL_REPLACE a bitmask of binary or'ed HTTP_URL constants; HTTP_URL_REPLACE is the default
$new_url (by reference) (untyped) array() if set, it will be filled with the parts of the composed url like parse_url() would return

Returns: (none declared) — string

str_to_bool()

public static function str_to_bool($string, $default = false)

lines 983–995 (13)

Converts many english words that equate to true or false to boolean.

Supports 'y', 'n', 'yes', 'no' and a few other variations.

Parameter Type Default Description
$string (untyped) required The string to convert to boolean
$default (untyped) false The value to return if we can't match any yes/no words

Returns: (none declared) — boolean

starts_with()

public static function starts_with($string, $starts_with)

lines 1004–1007 (4)

Check if a string starts with the given string.

Parameter Type Default Description
$string (untyped) required none
$starts_with (untyped) required none

Returns: (none declared) — boolean

ends_with()

public static function ends_with($string, $ends_with)

lines 1016–1019 (4)

Check if a string ends with the given string.

Parameter Type Default Description
$string (untyped) required none
$ends_with (untyped) required none

Returns: (none declared) — boolean

str_contains()

public static function str_contains($haystack, $needle)

lines 1028–1031 (4)

Check if a string contains another string.

Parameter Type Default Description
$haystack (untyped) required none
$needle (untyped) required none

Returns: (none declared) — boolean

str_icontains()

public static function str_icontains($haystack, $needle)

lines 1041–1044 (4)

Check if a string contains another string. This version is case

insensitive.

Parameter Type Default Description
$haystack (untyped) required none
$needle (untyped) required none

Returns: (none declared) — boolean

get_file_ext()

public static function get_file_ext($filename)

lines 1052–1055 (4)

Return the file extension of the given filename.

Parameter Type Default Description
$filename (untyped) required none

Returns: (none declared) — string

rmdir()

public static function rmdir($dir, $traverseSymlinks = false)

lines 1067–1109 (43)

Removes a directory (and its contents) recursively.

Contributed by Askar (ARACOOL) <https://github.com/ARACOOOL>

Parameter Type Default Description
$dir (untyped) required The directory to be deleted recursively
$traverseSymlinks (untyped) false Delete contents of symlinks recursively

Returns: (none declared) — bool

Throws: \RuntimeException

htmlentities()

public static function htmlentities($string, $preserve_encoded_entities = false)

lines 1117–1133 (17)

Convert entities, while preserving already-encoded entities.

Parameter Type Default Description
$string (untyped) required The text to be converted
$preserve_encoded_entities (untyped) false none

Returns: (none declared) — string

htmlspecialchars()

public static function htmlspecialchars($string, $preserve_encoded_entities = false)

lines 1142–1159 (18)

Convert >, <, ', ” and & to html entities, but preserves entities that

are already encoded.

Parameter Type Default Description
$string (untyped) required The text to be converted
$preserve_encoded_entities (untyped) false none

Returns: (none declared) — string

downcode()

public static function downcode($text, $language = &#039;&#039;)

lines 1172–1200 (29)

Transliterates characters to their ASCII equivalents.

Part of the URLify.php Project <https://github.com/jbroadway/urlify/>

Parameter Type Default Description
$text (untyped) required Text that might have not-ASCII characters
$language (untyped) '''''' Specifies a priority for a specific language.

Returns: (none declared) — string Filtered string with replaced “nice” characters

remove_accents()

public static function remove_accents($string, $language = &#039;&#039;)

lines 1212–1219 (8)

Converts all accent characters to ASCII characters.

If there are no accent characters, then the string given is just returned.

Parameter Type Default Description
$string (untyped) required Text that might have accent characters
$language (untyped) '''''' Specifies a priority for a specific language.

Returns: (none declared) — string Filtered string with replaced “nice” characters

strip_space()

public static function strip_space($string)

lines 1227–1230 (4)

Strip all witespaces from the given string.

Parameter Type Default Description
$string (untyped) required The string to strip

Returns: (none declared) — string

sanitize_string()

public static function sanitize_string($string)

lines 1242–1250 (9)

Sanitize a string by performing the following operation :

\- Remove accents \- Lower the string \- Remove punctuation characters \- Strip whitespaces

Parameter Type Default Description
$string (untyped) required the string to sanitize

Returns: (none declared) — string

zero_pad()

public static function zero_pad($number, $length)

lines 1259–1262 (4)

Pads a given string with zeroes on the left.

Parameter Type Default Description
$number (untyped) required The number to pad
$length (untyped) required The total length of the desired string

Returns: (none declared) — string

human_time_diff()

public static function human_time_diff($from, $to = &#039;&#039;, $as_text = false, $suffix = &#039; ago&#039;)

lines 1273–1319 (47)

Converts a unix timestamp to a relative time string, such as “3 days ago”

or “2 weeks ago”.

Parameter Type Default Description
$from (untyped) required The date to use as a starting point
$to (untyped) '''''' The date to compare to, defaults to now
$as_text (untyped) false none
$suffix (untyped) ''' ago''' The string to add to the end, defaults to “ ago”

Returns: (none declared) — string

number_to_word()

public static function number_to_word($number)

lines 1330–1384 (55)

Converts a number into the text equivalent. For example, 456 becomes four

hundred and fifty-six.

Part of the IntToWords Project.

Parameter Type Default Description
$number (untyped) required The number to convert into text

Returns: (none declared) — string

numberToWordConvertGroup()

protected static function numberToWordConvertGroup($index)

lines 1386–1416 (31)

Parameter Type Default Description
$index (untyped) required none

Returns: (none declared)

numberToWordThreeDigits()

protected static function numberToWordThreeDigits($digit1, $digit2, $digit3)

lines 1418–1440 (23)

Parameter Type Default Description
$digit1 (untyped) required none
$digit2 (untyped) required none
$digit3 (untyped) required none

Returns: (none declared)

numberToWordTwoDigits()

protected static function numberToWordTwoDigits($digit1, $digit2)

lines 1442–1508 (67)

Parameter Type Default Description
$digit1 (untyped) required none
$digit2 (untyped) required none

Returns: (none declared)

numberToWordConvertDigit()

protected static function numberToWordConvertDigit($digit)

lines 1515–1541 (27)

Parameter Type Default Description
$digit (untyped) required none

Returns: (none declared) — string

Throws: \LogicException

utf8_headers()

public static function utf8_headers($content_type = &#039;text/html&#039;)

lines 1549–1560 (12)

Transmit UTF-8 content headers if the headers haven't already been sent.

Parameter Type Default Description
$content_type (untyped) 'text/html' The content type to send out

Returns: (none declared) — boolean

force_download()

public static function force_download($filename, $content = false)

lines 1574–1610 (37)

Transmit headers that force a browser to display the download file

dialog. Cross browser compatible. Only fires if headers have not already been sent.

Parameter Type Default Description
$filename (untyped) required The name of the filename to display to browsers
$content (untyped) false The content to output for the download. If you don't specify this, just the headers will be sent

Returns: (none declared) — boolean

nocache_headers()

public static function nocache_headers()

lines 1621–1635 (15)

Sets the headers to prevent caching for the different browsers.

Different browsers support different nocache headers, so several headers must be sent so that all of them get the point that no caching should occur

Takes no parameters.

Returns: (none declared) — boolean

random_string()

public static function random_string($length = 16, $human_friendly = true, $include_symbols = false, $no_duplicate_chars = false)

lines 1659–1709 (51)

Generates a string of random characters.

Parameter Type Default Description
$length (untyped) 16 The length of the string to generate
$human_friendly (untyped) true Whether or not to make the string human friendly by removing characters that can be confused with other characters ( O and 0, l and 1, etc)
$include_symbols (untyped) false Whether or not to include symbols in the string. Can not be enabled if $human_friendly is true
$no_duplicate_chars (untyped) false Whether or not to only use characters once in the string.

Returns: (none declared) — string

Throws: LengthException

secure_random_string()

public static function secure_random_string($length = 16)

lines 1721–1736 (16)

Generate secure random string of given length

If 'openssl_random_pseudo_bytes' is not available then generate random string using default function

Part of the Laravel Project <https://github.com/laravel/laravel>

Parameter Type Default Description
$length (untyped) 16 length of string

Returns: (none declared) — bool

match_string()

public static function match_string($pattern, $string, $caseSensitive = true)

lines 1747–1763 (17)

Check if a given string matches a given pattern.

Contributed by Abhimanyu Sharma <https://github.com/abhimanyusharma003>

Parameter Type Default Description
$pattern (untyped) required Parttern of string exptected
$string (untyped) required String that need to be matched
$caseSensitive (untyped) true none

Returns: (none declared) — bool

validate_email()

public static function validate_email($possible_email)

lines 1771–1774 (4)

Validate an email address.

Parameter Type Default Description
$possible_email (untyped) required An email address to validate

Returns: (none declared) — bool

get_gravatar()

public static function get_gravatar($email, $size = 32)

lines 1783–1794 (12)

Return the URL to a user's gravatar.

Parameter Type Default Description
$email (untyped) required The email of the user
$size (untyped) 32 The size of the gravatar

Returns: (none declared) — string

linkify()

public static function linkify($text)

lines 1804–1821 (18)

Turns all of the links in a string into HTML links.

Part of the LinkifyURL Project <https://github.com/jmrware/LinkifyURL>

Parameter Type Default Description
$text (untyped) required The string to parse

Returns: (none declared) — string

linkifyRegex()

protected static function linkifyRegex($text)

lines 1831–1877 (47)

Callback for the preg_replace in the linkify() method.

Part of the LinkifyURL Project <https://github.com/jmrware/LinkifyURL>

Parameter Type Default Description
$text (untyped) required none

Returns: (none declared) — string

linkifyCallback()

protected static function linkifyCallback($matches)

lines 1887–1894 (8)

Callback for the preg_replace in the linkify() method.

Part of the LinkifyURL Project <https://github.com/jmrware/LinkifyURL>

Parameter Type Default Description
$matches (untyped) required Matches from the preg_ function

Returns: (none declared) — string

get_current_url()

public static function get_current_url()

lines 1901–1952 (52)

Return the current URL.

Takes no parameters.

Returns: (none declared) — string

get_client_ip()

public static function get_client_ip($trust_proxy_headers = false)

lines 1964–1979 (16)

Returns the IP address of the client.

Parameter Type Default Description
$trust_proxy_headers (untyped) false Whether or not to trust the proxy headers HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR. ONLY use if your server is behind a proxy that sets these values

Returns: (none declared) — string

safe_truncate()

public static function safe_truncate($string, $length, $append = &#039;...&#039;)

lines 1990–2004 (15)

Truncate a string to a specified length without cutting a word off.

Parameter Type Default Description
$string (untyped) required The string to truncate
$length (untyped) required The length to truncate the string to
$append (untyped) '…' Text to append to the string IF it gets truncated, defaults to '…'

Returns: (none declared) — string

limit_characters()

public static function limit_characters($string, $limit = 100, $append = &#039;...&#039;)

lines 2015–2022 (8)

Truncate the string to given length of charactes.

Parameter Type Default Description
$string (untyped) required none
$limit (untyped) 100 none
$append (untyped) '…' none

Returns: (none declared) — string

limit_words()

public static function limit_words($string, $limit = 100, $append = &#039;...&#039;)

lines 2032–2041 (10)

Truncate the string to given length of words.

Parameter Type Default Description
$string (untyped) required none
$limit (untyped) 100 none
$append (untyped) '…' none

Returns: (none declared) — string

ordinal()

public static function ordinal($number, $locale)

lines 2049–2057 (9)

Returns the ordinal version of a number (appends th, st, nd, rd).

Parameter Type Default Description
$number (untyped) required The number to append an ordinal suffix to
$locale (untyped) required none

Returns: (none declared) — string

full_permissions()

public static function full_permissions($file, $perms = null)

lines 2067–2124 (58)

Returns the file permissions as a nice string, like -rw-r–r– or false

if the file is not found.

Parameter Type Default Description
$file (untyped) required The name of the file to get permissions form
$perms (untyped) null Numerical value of permissions to display as text.

Returns: (none declared) — string

array_first()

public static function array_first(array $array)

lines 2132–2135 (4)

Returns the first element in an array.

Parameter Type Default Description
$array array required none

Returns: (none declared) — mixed

array_last()

public static function array_last(array $array)

lines 2143–2146 (4)

Returns the last element in an array.

Parameter Type Default Description
$array array required none

Returns: (none declared) — mixed

array_first_key()

public static function array_first_key(array $array)

lines 2154–2159 (6)

Returns the first key in an array.

Parameter Type Default Description
$array array required none

Returns: (none declared) — int&#124;string

array_last_key()

public static function array_last_key(array $array)

lines 2167–2172 (6)

Returns the last key in an array.

Parameter Type Default Description
$array array required none

Returns: (none declared) — int&#124;string

array_flatten()

public static function array_flatten(array $array, $preserve_keys = true)

lines 2185–2198 (14)

Flatten a multi-dimensional array into a one dimensional array.

Contributed by Theodore R. Smith of PHP Experts, Inc. <http://www.phpexperts.pro/>

Parameter Type Default Description
$array array required The array to flatten
$preserve_keys (untyped) true Whether or not to preserve array keys. Keys from deeply nested arrays will overwrite keys from shallowy nested arrays

Returns: (none declared) — array

array_pluck()

public static function array_pluck(array $array, $field, $preserve_keys = true, $remove_nomatches = true)

lines 2214–2243 (30)

Accepts an array, and returns an array of values from that array as

specified by $field. For example, if the array is full of objects and you call util::array_pluck($array, 'name'), the function will return an array of values from $array[]→name.

Parameter Type Default Description
$array array required An array
$field (untyped) required The field to get values from
$preserve_keys (untyped) true Whether or not to preserve the array keys
$remove_nomatches (untyped) true If the field doesn't appear to be set, remove it from the array

Returns: (none declared) — array

array_search_deep()

public static function array_search_deep(array $array, $search, $field = false)

lines 2256–2289 (34)

Searches for a given value in an array of arrays, objects and scalar

values. You can optionally specify a field of the nested arrays and objects to search in.

Parameter Type Default Description
$array array required The array to search
$search (untyped) required The value to search for
$field (untyped) false The field to search in, if not specified all fields will be searched

Returns: (none declared) — boolean&#124;scalar False on failure or the array key on success

array_map_deep()

public static function array_map_deep(array $array, $callback, $on_nonscalar = false)

lines 2304–2316 (13)

Returns an array containing all the elements of arr1 after applying

the callback function to each one.

Parameter Type Default Description
$array array required An array to run through the callback function
$callback (untyped) required Callback function to run for each element in each array
$on_nonscalar (untyped) false Whether or not to call the callback function on nonscalar values (Objects, resources, etc)

Returns: (none declared) — array

array_clean()

public static function array_clean(array $array)

lines 2318–2321 (4)

Parameter Type Default Description
$array array required none

Returns: (none declared)

mbInternalEncoding()

protected static function mbInternalEncoding($encoding = null)

lines 2330–2339 (10)

Wrapper to prevent errors if the user doesn't have the mbstring

extension installed.

Parameter Type Default Description
$encoding (untyped) null none

Returns: (none declared) — string

set_writable()

public static function set_writable($filename, $writable = true)

lines 2349–2391 (43)

Set the writable bit on a file to the minimum value that allows the user

running PHP to write to it.

Parameter Type Default Description
$filename (untyped) required The filename to set the writable bit on
$writable (untyped) true Whether to make the file writable or not

Returns: (none declared) — boolean

set_readable()

public static function set_readable($filename, $readable = true)

lines 2401–2443 (43)

Set the readable bit on a file to the minimum value that allows the user

running PHP to read to it.

Parameter Type Default Description
$filename (untyped) required The filename to set the readable bit on
$readable (untyped) true Whether to make the file readable or not

Returns: (none declared) — boolean

set_executable()

public static function set_executable($filename, $executable = true)

lines 2453–2495 (43)

Set the executable bit on a file to the minimum value that allows the

user running PHP to read to it.

Parameter Type Default Description
$filename (untyped) required The filename to set the executable bit on
$executable (untyped) true Whether to make the file executable or not

Returns: (none declared) — boolean

directory_size()

public static function directory_size($dir)

lines 2503–2512 (10)

Returns size of a given directory in bytes.

Parameter Type Default Description
$dir (untyped) required none

Returns: (none declared) — integer

get_user_directory()

public static function get_user_directory()

lines 2519–2526 (8)

Returns a home directory of current user.

Takes no parameters.

Returns: (none declared) — string

directory_contents()

public static function directory_contents($dir)

lines 2534–2542 (9)

Returns all paths inside a directory.

Parameter Type Default Description
$dir (untyped) required none

Returns: (none declared) — array


This page is generated from source by 'tools/gendoc'. Edits will be overwritten.

scriptlog/lib/core/util.txt · Last modified: by admin