PHPackages                             omnicode/php-util - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. omnicode/php-util

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

omnicode/php-util
=================

PHP Utility functions

5.0.0(8y ago)212.3k12MITPHPPHP &gt;=5.3.0

Since May 18Pushed 7y agoCompare

[ Source](https://github.com/omnicode/php-util)[ Packagist](https://packagist.org/packages/omnicode/php-util)[ RSS](/packages/omnicode-php-util/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (1)Versions (19)Used By (2)

[![Build Status](https://camo.githubusercontent.com/bacbcd9a34bc3bc5690b0432d9bf55f19f67d8212b21fefb05dbe7dc10fd5cc5/68747470733a2f2f7472617669732d63692e6f72672f6f6d6e69636f64652f7068702d7574696c2e737667)](https://travis-ci.org/omnicode/php-util)[![Total Downloads](https://camo.githubusercontent.com/1992920857e3f6a801776fbf204760bc3a3c8ac7064168ee760a97c0a1629f21/68747470733a2f2f706f7365722e707567782e6f72672f6f6d6e69636f64652f7068702d7574696c2f642f746f74616c2e737667)](https://packagist.org/packages/omnicode/php-util)[![Latest Stable Version](https://camo.githubusercontent.com/774c82a645e4dd10965e5cb03c6ef664ad6a5f2f82fba8b852a80243b4953205/68747470733a2f2f706f7365722e707567782e6f72672f6f6d6e69636f64652f7068702d7574696c2f762f737461626c652e737667)](https://packagist.org/packages/omnicode/php-util)[![License](https://camo.githubusercontent.com/2817df2a4b79f455b093276cded59e1ff56e10aad0b1a3669d7ebd28dfc8af3f/68747470733a2f2f706f7365722e707567782e6f72672f6f6d6e69636f64652f7068702d7574696c2f6c6963656e73652e737667)](https://packagist.org/packages/omnicode/php-util)

Utility Functions for PHP
=========================

[](#utility-functions-for-php)

Functions are added to global namespace

Contents
--------

[](#contents)

- [dbg](#dbg)
- [h](#h)
- [is\_natural](#is_natural)
- [between](#between)
- [is\_numeric\_list](#is_numeric_list)
- [last\_chars](#last_chars)
- [create\_slug](#create_slug)
- [coalesce](#coalesce)
- [get\_first\_key](#get_first_fey)
- [get\_first\_value](#get_first_value)
- [get\_last\_key](#get_last_key)
- [get\_last\_value](#get_last_value)
- [array\_unset](#array_unset)
- [array\_iunique](#array_iunique)
- [get\_directory\_size](#get_directory_size)
- [get\_file\_name](#get_file_name)
- [get\_file\_extension](#get_file_extension)
- [check\_file\_exists](#check_file_exists)
- [format\_bytes](#format_bytes)
- [datetotime](#datetotime)
- [is\_date](#is_date)
- [t2d](#t2d)
- [t2dt](#t2dt)
- [get\_range](#get_range)
- [\_humanize](#_humanize)
- [get\_class\_constant](#get_class_constant)
- [get\_class\_constants](#get_class_constants)
- [shorten](#shorten)
- [safe\_json\_encode](#safe_json_encode)
- [get\_client\_ip](#get_client_ip)
- [rm\_rf](#rm_rf)
- [copy\_r](#copy_r)
- [get\_query\_params](#get_query_params)
- [get\_class\_name](#get_class_name)
- [extract\_number](#extract_number)
- [seconds\_to\_hour\_minute](#seconds_to_hour_minute)
- [is\_cli](#is_cli)

### dbg

[](#dbg)

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

```

### h

[](#h)

```
/**
 * Convenience method for htmlspecialchars.
 *
 * @param string|array|object $text Text to wrap through htmlspecialchars. Also works with arrays, and objects.
 *    Arrays will be mapped and have all their elements escaped. Objects will be string cast if they
 *    implement a `__toString` method. Otherwise the class name will be used.
 * @param bool $double Encode existing html entities.
 * @param string|null $charset Character set to use when escaping. Defaults to config value in `mb_internal_encoding()`
 * or 'UTF-8'.
 * @return string Wrapped text.
 * @link http://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#h
 */
function h($text, $double = true, $charset = null)

```

### is\_natural

[](#is_natural)

```
/**
 * 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)

```

###  between

[](#-between)

```
/**
 * 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)

```

### is\_numeric\_list

[](#is_numeric_list)

```
/**
 * 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)

```

### last\_chars

[](#last_chars)

```
/**
 * returns given amount of characters counting backwards
 *
 * @param string $str
 * @param int $count
 * @return string
 */
function last_chars($str, $count = 1)

```

### create\_slug

[](#create_slug)

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

```

### coalesce

[](#coalesce)

```
/**
 * mysql coalesce equivalent
 *
 * @param mixed - list of arguments
 * @return mixed
 * @link http://stackoverflow.com/a/4688108/932473
 */
function coalesce()

```

### get\_first\_key

[](#get_first_key)

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

```

### get\_first\_value

[](#get_first_value)

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

```

### get\_last\_key

[](#get_last_key)

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

```

### get\_last\_value

[](#get_last_value)

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

```

### array\_unset

[](#array_unset)

```
/**
 * 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 = [])

```

### array\_iunique

[](#array_iunique)

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

```

### get\_directory\_size

[](#get_directory_size)

```
/**
 * returns the size of the directory
 *
 * @param null $path
 * @param bool|false $unit
 * @param bool|false $intOnly
 * @return string
 * @throws Exception
 * @link http://stackoverflow.com/a/478161/932473
 */
function get_directory_size($path = null, $unit = false, $intOnly = false)

```

### get\_file\_name

[](#get_file_name)

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

```

### get\_file\_extension

[](#get_file_extension)

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

```

### check\_file\_exists

[](#check_file_exists)

```
/**
 * 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)

```

### format\_bytes

[](#format_bytes)

```
/**
 * @param $bytes
 * @param int $precision
 * @return string
 * @link http://stackoverflow.com/a/2510459/932473
 */
function format_bytes($bytes, $precision = 0)

```

### datetotime

[](#datetotime)

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

```

### is\_date

[](#is_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)

```

### t2d

[](#t2d)

```
/**
 * returns date in Y-m-d format from seconds
 *
 * @param time $timeStr
 * @return date
 */
function t2d($timeStr = null)

```

### t2dt

[](#t2dt)

```
/**
 * returns date in Y-m-d H:i:s format from seconds
 *
 * @param time $timeStr
 * @return datetime
 */
function t2dt($timeStr = null)

```

### get\_range

[](#get_range)

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

```

### \_humanize

[](#_humanize)

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

```

### get\_class\_constant

[](#get_class_constant)

```
/**
 * 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)

```

### get\_class\_constants

[](#get_class_constants)

```
/**
 * 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)

```

### shorten

[](#shorten)

```
/**
 * returns the short string based on $length if string's length is more than $length
 *
 * @param string $str
 * @param number $length
 * @param bool $raw
 * @return string
 */
function shorten($str = '', $length = null, $raw = false)

```

### safe\_json\_encode

[](#safe_json_encode)

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

```

### get\_client\_ip

[](#get_client_ip)

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

```

### rm\_rf

[](#rm_rf)

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

```

### copy\_r

[](#copy_r)

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

```

### get\_query\_params

[](#get_query_params)

```
/**
 * parses the url and returns the specified or all list of params
 *
 * @access public
 * @param string $url
 * @param bool $onlyQuery - if true the param will be checked only in the query string, default - false
 * @return mixed - string if found the param, bool false otherwise
 */
function get_query_params($url, $param = '', $onlyQuery = false)

```

### get\_class\_name

[](#get_class_name)

```
/**
 * returns class name from object - without namespace
 *
 * @param string $object
 * @return mixed
 */
function get_class_name($object = '')

```

### extract\_number

[](#extract_number)

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

```

### seconds\_to\_hour\_minute

[](#seconds_to_hour_minute)

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

```

### is\_cli

[](#is_cli)

```
/**
 * check if the current request is from CLI
 *
 * @return bool
 */
function is_cli()

```

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 66.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~20 days

Recently: every ~0 days

Total

16

Last Release

2989d ago

Major Versions

v4.x-dev → v5.x-dev2018-03-09

0.1.0 → 1.0.02018-03-09

1.0.0 → 3.0.02018-03-09

3.0.0 → 4.0.02018-03-09

4.0.0 → 5.0.02018-03-09

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/24301583?v=4)[OMNICODE AI](/maintainers/omnicode)[@omnicode](https://github.com/omnicode)

---

Top Contributors

[![tig3](https://avatars.githubusercontent.com/u/24285332?v=4)](https://github.com/tig3 "tig3 (18 commits)")[![davitbek](https://avatars.githubusercontent.com/u/25708533?v=4)](https://github.com/davitbek "davitbek (9 commits)")

---

Tags

functionsphputilityphputilityfunctionsuseful

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/omnicode-php-util/health.svg)

```
[![Health](https://phpackages.com/badges/omnicode-php-util/health.svg)](https://phpackages.com/packages/omnicode-php-util)
```

###  Alternatives

[maciejczyzewski/bottomline

A full-on PHP manipulation utility belt that provides support for working with arrays, objects, and iterables; a lodash or underscore equivalent for PHP.

477631.4k10](/packages/maciejczyzewski-bottomline)[bdelespierre/underscore

Underscore.js port in PHP

6943.7k1](/packages/bdelespierre-underscore)[nilportugues/php_todo

Looks into the code using a user-defined list of to-do phrases and stops commit if the total amount increased or is above a threshold.

1210.0k](/packages/nilportugues-php-todo)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
