PHP code example of omnicode / php-util

1. Go to this page and download the library: Download omnicode/php-util library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

omnicode / php-util example snippets


/**
 * debug method from Cakephp - convenient wrapper for print_r
 *
 * @param $var
 * @param bool|false $return
 * @return string
 */
function dbg($var, $return = false)

/**
 * checks if the given number is a natural number
 *
 * @param int|float|array $number
 * @param bool $zero - if set to true zero will be considered
 * @return bool
 */
function is_natural($number, $zero = false)

/**
 * checks if the given value is between 2 values(inclusive)
 *
 * @param int $number
 * @param int $min
 * @param int $max
 * @return bool
 */
function between($number, $min, $max)

/**
 * if an array is provided checks the values of the array all to be numeric,
 * if string is provided, will check to be comma separated list
 *
 * @param mixed $data - array of numbers or string as comma separated numbers
 * @return bool
 */
function is_numeric_list($data)

/**
 * create slug from string
 *
 * @param string $str
 * @param string $symbol
 * @return string - e.g. in word1-word2-word3 format
 */
function create_slug($str = "", $symbol = "-")

/**
 * returns the first key of the array
 *
 * @param array $array
 * @return mixed
 */
function get_first_key(array $array = [])

/**
 * returns the first value of the array
 *
 * @param array $array
 * @return mixed
 */
function get_first_value($array)

/**
 * returns the last key of the array
 *
 * @param array $array
 * @return mixed
 */
function get_last_key($array)

/**
 * returns the last value of the array
 *
 * @param array $array
 * @return mixed
 */
function get_last_value($array)

/**
 * unsets array's items by value
 *
 * @param array $array - the original array
 * @param array|string - the value or array of values to be unset
 * @return array - the processed array
 */
function array_unset($array, $values = [])

/**
 * case-insensitive array_unique
 *
 * @param array
 * @return array
 * @link http://stackoverflow.com/a/2276400/932473
 */
function array_iunique($array)

/**
 * returns the file name without the extension
 *
 * @param string $fileName
 * @return string
 */
function get_file_name($fileName = '')

/**
 * returns the file extension from full file name
 *
 * @param string $fileName
 * @return string
 */
function get_file_extension($fileName)

/**
 * if file exists will return it - with number concatenated
 *
 * @param $path
 * @param $fileName
 * @param int $n
 * @return bool|string
 */
function check_file_exists($path, $fileName, $n = 100)

/**
 * return timestamp from date considering "/" delimiter
 *
 * @return string
 */
function datetotime($date)

/**
 * checks if the given date(s) are valid mysql dates
 *
 * @param null $date1
 * @param null $date
 * @return bool - true if all dates are valid, false otherwise
 */
function is_date($date1 = null, $date = null)

/**
 * returns array with options for select box
 *
 * @param $min
 * @param $max
 * @param int $step
 * @return array
 */
function get_range($min, $max, $step = 1)

/**
 * @param $val
 * @return string
 */
function _humanize($val)

/**
 * returns constant of the class based on its value
 *
 * @param $className
 * @param $value
 * @param bool|true $humanize
 * @return string
 * @throws Exception
 */
function get_class_constant($className, $value, $humanize = true)

/**
 * returns the list of constants of the given class
 *
 * @param $className
 * @param bool|false $reverse
 * @param bool|true $humanize
 * @return array
 * @throws Exception
 */
function get_class_constants($className, $reverse = false, $humanize = true)

/**
 * safe json_encode
 *
 * @param string $value
 * @return string
 */
function safe_json_encode($value)

/**
 * get client ip
 *
 * @return string
 */
function get_client_ip()

/**
 * linux "rm -rf" command equivalent
 * recursively deletes directory
 *
 * @param string $path
 * @throws Exception
 * @return bool
 */
function rm_rf($path)

/**
 * recursively copies files and directories
 *
 * @param string $src
 * @param string $dst
 * @return bool
 */
function copy_r($src, $dst)

/**
 * returns numbers from the string
 *
 * @param string $str
 * @return string
 */
function extract_number($str = '')

/**
 * converts given seconds to hours and minutes
 *
 * @param null $seconds
 * @return string
 */
function seconds_to_hour_minute($seconds = null)