\TriTan\CommonUtils

Summary

Methods
Properties
Constants
__construct()
stripslashesDeep()
unslash()
absint()
ifNull()
flattenArray()
trim()
escape()
parseStr()
parseArgs()
stripTags()
toObject()
$hook
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$hook

$hook : 

Type

Methods

stripslashesDeep()

stripslashesDeep(mixed  $value) : mixed

Navigates through an array, object, or scalar, and removes slashes from the values.

Parameters

mixed $value

The value to be stripped.

Returns

mixed —

Stripped value.

unslash()

unslash(  $value) : string|array

This should be used to remove slashes from data passed to core API that expects data to be unslashed.

Parameters

$value

Returns

string|array —

Unslashed value.

absint()

absint(mixed  $maybeint) : integer

Convert a value to non-negative integer.

Parameters

mixed $maybeint

Data you wish to have converted to a non-negative integer.

Returns

integer —

A non-negative integer.

ifNull()

ifNull(string|integer  $var) : string|integer|null

Checks if a variable is null. If not null, check if integer or string.

Parameters

string|integer $var

Variable to check.

Returns

string|integer|null —

Returns null if empty otherwise a string or an integer.

flattenArray()

flattenArray(array  $array) : array

Turns multi-dimensional array into a regular array.

Parameters

array $array

The array to convert.

Returns

array

trim()

trim(string  $str) : mixed

Removes all whitespace.

Parameters

string $str

Returns

mixed

escape()

escape(string  $str) : mixed

Renders any unwarranted special characters to HTML entities.

Parameters

string $str

Returns

mixed

parseStr()

parseStr(string  $string, array  $array) 

Parses a string into variables to be stored in an array.

Uses parse_str()

Parameters

string $string

The string to be parsed.

array $array

Variables will be stored in this array.

parseArgs()

parseArgs(string|array  $args, array  $defaults = '') : array

Merge user defined arguments into defaults array.

This method is used throughout TriTan CMS to allow for both string or array to be merged into another array.

Parameters

string|array $args

Value to merge with $defaults

array $defaults

Optional. Array that serves as the defaults. Default empty.

Returns

array —

Merged user defined values with defaults.

stripTags()

stripTags(string  $string, boolean  $remove_breaks = false, string  $tags = '', boolean  $invert = false) : string

Properly strip all HTML tags including script and style (default).

This differs from PHP's native strip_tags() function because this function removes the contents of the <script> and <style> tags. E.g. strip_tags( '<script>something</script>' ) will return 'something'. By default, $this->stripTags() will return ''.

Example Usage:

 $string = '<b>sample</b> text with <div>tags</div>';

 $this->stripTags($string); //returns 'text with'
 $this->stripTags($string, false, '<b>'); //returns '<b>sample</b> text with'
 $this->stripTags($string, false, '<b>', true); //returns 'text with <div>tags</div>'

Parameters

string $string

String containing HTML tags

boolean $remove_breaks

Optional. Whether to remove left over line breaks and white space chars

string $tags

Tags that should be removed.

boolean $invert

Instead of removing tags, this option checks for which tags to not remove. Default: false;

Returns

string —

The processed string.

toObject()

toObject(array  $array) 

Takes an array and turns it into an object.

Parameters

array $array

Array of data.