ratatoeskr/sys/utils.php

Various useful helper functions.

License

This file is part of Ratatöskr.  Ratatöskr is licensed unter the MIT / X11 License.  See “ratatoeskr/licenses/ratatoeskr” for more information.

Summary
ratatoeskr/sys/utils.phpVarious useful helper functions.
Functions
array_repeat$val - $n -
array_blendBlend multiple arrays together.
array_filter_emptyFilters all empty elements out of an array.
array_filter_keysLike PHPs `array_filter`, but callback will get the key, not the value of the array element.
array_kvpairs_to_assocConvert array of key-value pairs to an associative array.
intcmpCompare integers (equavilent to strcmp)
ucountCount elements of an array matching unser-defined rules.
vcountCounts how often $value appears in $array.
self_urlGets current URL.
htmlescEscape HTML (shorter than htmlspecialchars)
delete_directoryDelete a directory and all of its content.
Constants
SITE_BASE_PATHThe Base path of this ratatoeskr site.

Functions

array_repeat

function array_repeat($val,
$n)

Parameters

$val - $n -

Returns

An array with $val $n-times repeated.

array_blend

function array_blend()

Blend multiple arrays together.

Example

array_blend(array(1,2,3), array(4,5,6), array(7,8,9)); will return array(1,4,7,2,5,8,3,6,9)

array_filter_empty

function array_filter_empty($input)

Filters all empty elements out of an array.

Parameters

$inputThe input array

Returns

The $input without its empty elements.

array_filter_keys

function array_filter_keys($input,
$callback)

Like PHPs `array_filter`, but callback will get the key, not the value of the array element.

array_kvpairs_to_assoc

function array_kvpairs_to_assoc($input)

Convert array of key-value pairs to an associative array.

Parameters

$inputArray of key-value pairs

Returns

An associative array.

intcmp

function intcmp($a,
$b)

Compare integers (equavilent to strcmp)

ucount

function ucount($array,
$callback)

Count elements of an array matching unser-defined rules.

Parameters

$arrayThe input array.
$callbackA callback function.  It will be called with the current value as the only parameter.  The value is counted, if callback returns TRUE.

Returns

Number of elements where $callback returned TRUE.

vcount

function vcount($array,
$value)

Counts how often $value appears in $array.

Parameters

$array - $value -

Returns

How often $value appears in $array.

self_url

function self_url()

Gets current URL.

From: http://dev.kanngard.net/Permalinks/ID_20050507183447.html

htmlesc

function htmlesc($text)

Escape HTML (shorter than htmlspecialchars)

Parameters

$textInput text.

Returns

HTML

delete_directory

function delete_directory($dir)

Delete a directory and all of its content.

Constants

SITE_BASE_PATH

The Base path of this ratatoeskr site.

function array_repeat($val,
$n)
$val - $n -
function array_blend()
Blend multiple arrays together.
function array_filter_empty($input)
Filters all empty elements out of an array.
function array_filter_keys($input,
$callback)
Like PHPs `array_filter`, but callback will get the key, not the value of the array element.
function array_kvpairs_to_assoc($input)
Convert array of key-value pairs to an associative array.
function intcmp($a,
$b)
Compare integers (equavilent to strcmp)
function ucount($array,
$callback)
Count elements of an array matching unser-defined rules.
function vcount($array,
$value)
Counts how often $value appears in $array.
function self_url()
Gets current URL.
function htmlesc($text)
Escape HTML (shorter than htmlspecialchars)
function delete_directory($dir)
Delete a directory and all of its content.
Close