Class SqueakyMindsPhpHelper

This class provides helper methods I have developed or acquired over the years.

package SqueakyMindsPhpHelper

 Methods

Return the first array member.

array_first(array $array_val) : array
Static
method
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$array_val

array

Exceptions

\InvalidArgumentException Not array data.

Returns

array

Return the last array member.

array_last(array $array_val) : array
Static
method Return the last array member.
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$array_val

array

Array data.

Exceptions

\InvalidArgumentException Not array data.

Returns

array

Convert BR tags to PHP_EOL.

br2nl(string $string) : string
Static
method Convert BR tags to PHP_EOL.
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$string

string

The string to convert

Returns

stringThe converted string

Prevent undefined cookie variables

cookievar($name, boolean $isint = false) : array | integer | string
Static
method Prevent undefined cookie variables
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$name

$isint

boolean

Returns

arrayintegerstring

HTML Dump of string/array/etc.

dump_simple_array(mixed $array, string $title = "") : string
Static
method HTML Dump of string/array/etc.
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$array

mixed

Data to dump.

$title

string

Table title.

Returns

string

Return duration from seconds.

duration(integer $secs) : string
Static
method Return duration from seconds.
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$secs

integer

Seconds value.

Returns

string

Escape a string just like mysql_escape_string which is now depreciated.

escape($inp) : string
Static
method Escape a string just like mysql_escape_string which is now depreciated.
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$inp

Returns

string

Prevent undefined get variables

getvar($name, boolean $isint = false) : integer | mixed | string
Static
method Prevent undefined get variables
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$name

$isint

boolean

Returns

integermixedstring

Return getvar with a default when blank.

getvar_default(string $field_name, mixed $default_val = "") : mixed
Static
method Return getvar with a default is blank.
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$field_name

string

$_GET variable key name.

$default_val

mixed

The default value returned in the event the $_GET variable is empty or does not exist.

Returns

mixed

Indents a flat JSON string to make it more human-readable.

json_indent(string $json) : string
method
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$json

string

The original JSON string to process.

Returns

stringIndented version of the original JSON string.

Return characters from the left

left(string $str, integer $howManyCharsFromLeft) : string
Static
method Return characters from the left.
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$str

string

String to truncate.

$howManyCharsFromLeft

integer

Number of characters to the left of the string.

Returns

string

Turn all URLs in clickable links.

linkify($value) : string
Static
method )
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$value

Returns

string

Return x many characters from the starting point

mid(string $str, integer $start, integer $howManyChars = 0) : string
Static
method Return x many characters from the starting point
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$str

string

String to truncate.

$start

integer

Where to start from the left of the string.

$howManyChars

integer

Number of characters to return.

Returns

string

Return array stripslasshes recursive.

multi_stripslashes(callable $arr) 
Static
method Return array stripslasshes recursive.
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$arr

callable

Input array.

Return roman numeral.

numberToRoman(integer $num) : string
Static
method Return roman numeral.
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$num

integer

Number to transform.

Returns

string

Return an array from an object.

object2array(object $object) : array
Static
method Return an array from an object.
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$object

object

Object to transform.

Returns

array

Prevent undefined post variables

postvar($name, boolean $isint = false) : integer | mixed | string
Static
method Prevent undefined post variables
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$name

$isint

boolean

Returns

integermixedstring

Return postvar with a default when blank.

postvar_default(string $field_name, mixed $default_val = "") : mixed
Static
method Return postvar with a default is blank.
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$field_name

string

$_POST variable key name.

$default_val

mixed

The default value returned in the event the $_POST variable is empty or does not exist.

Returns

mixed

Return the requested url.

requested_url() : string
Static
method
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Returns

string

Return characters from the right

right(string $str, integer $howManyCharsFromRight) : string
Static
method Return characters from the right.
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$str

string

String to truncate.

$howManyCharsFromRight

integer

Number of characters to the right of the string.

Returns

string

Send header stuff that tells the browser not to cache this page.

send_no_cache_header() 
Static
method
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Prevent undefined server variables

servervar($name, boolean $isint = false) : array | integer | string
Static
method Prevent undefined servervar variables
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$name

$isint

boolean

Returns

arrayintegerstring

Prevent undefined session variables

sessionvar(string $name, boolean $isint = false) : mixed
Static
method Prevent undefined session variables
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$name

string

$_SESSION variable key

$isint

boolean

Response if an integer

Returns

mixed

Set session variables

setsessionvar(string $name, boolean $value) 
Static
method
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$name

string

$_SESSION variable key

$value

boolean

$_SESSION variable value

Truncate a string.

stringTruncate(string $string, integer $limit, string $break = ".", string $pad = "...") : string
Static
method Truncate a string.
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$string

string

The string to truncate.

$limit

integer

String length max.

$break

string

(optional) Break point, defauls to period.

$pad

string

(optional) String to append to the truncated string.

Returns

stringTruncated string.

Return truncated number.

truncate(integer $num, integer $digits = 0) : integer
Static
method Return truncated number.
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$num

integer

Number to truncate.

$digits

integer

Number of digits to truncate.

Returns

integer

Return a 32 bit unique ID

uuid() : string
Static
method Return a 32 bit unique ID
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Returns

string32 character unique ID.

Return an array from xml string.

xml2array(string $xmlstring) : array
Static
method Return an array from xml string.
access public
author Brian Tafoya
copyright Copyright 2001 - 2017, Brian Tafoya.
version 1.0

Parameters

$xmlstring

string

XML to process.

Returns

array