{"id":19691548,"url":"https://github.com/omnicode/php-util","last_synced_at":"2025-09-03T05:44:01.368Z","repository":{"id":57031337,"uuid":"91724170","full_name":"omnicode/php-util","owner":"omnicode","description":"Utility functions for php","archived":false,"fork":false,"pushed_at":"2019-05-02T07:16:54.000Z","size":34,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-03T05:44:00.648Z","etag":null,"topics":["functions","php","utility"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/omnicode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-18T18:12:10.000Z","updated_at":"2021-08-06T11:19:04.000Z","dependencies_parsed_at":"2022-08-23T18:50:49.632Z","dependency_job_id":null,"html_url":"https://github.com/omnicode/php-util","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/omnicode/php-util","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omnicode%2Fphp-util","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omnicode%2Fphp-util/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omnicode%2Fphp-util/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omnicode%2Fphp-util/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/omnicode","download_url":"https://codeload.github.com/omnicode/php-util/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omnicode%2Fphp-util/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273397843,"owners_count":25098234,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-03T02:00:09.631Z","response_time":76,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["functions","php","utility"],"created_at":"2024-11-11T19:09:45.645Z","updated_at":"2025-09-03T05:44:01.349Z","avatar_url":"https://github.com/omnicode.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://travis-ci.org/omnicode/php-util\"\u003e\u003cimg src=\"https://travis-ci.org/omnicode/php-util.svg\" alt=\"Build Status\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/omnicode/php-util\"\u003e\u003cimg src=\"https://poser.pugx.org/omnicode/php-util/d/total.svg\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/omnicode/php-util\"\u003e\u003cimg src=\"https://poser.pugx.org/omnicode/php-util/v/stable.svg\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/omnicode/php-util\"\u003e\u003cimg src=\"https://poser.pugx.org/omnicode/php-util/license.svg\" alt=\"License\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n# Utility Functions for PHP\n\nFunctions are added to global namespace\n\n## Contents\n\n* \u003ca href=\"#dbg\"\u003edbg\u003c/a\u003e\n* \u003ca href=\"#h\"\u003eh\u003c/a\u003e\n* \u003ca href=\"#is_natural\"\u003eis_natural\u003c/a\u003e\n* \u003ca href=\"#between\"\u003ebetween\u003c/a\u003e\n* \u003ca href=\"#is_numeric_list\"\u003eis_numeric_list\u003c/a\u003e\n* \u003ca href=\"#last_chars\"\u003elast_chars\u003c/a\u003e\n* \u003ca href=\"#create_slug\"\u003ecreate_slug\u003c/a\u003e\n* \u003ca href=\"#coalesce\"\u003ecoalesce\u003c/a\u003e\n* \u003ca href=\"#get_first_fey\"\u003eget_first_key\u003c/a\u003e\n* \u003ca href=\"#get_first_value\"\u003eget_first_value\u003c/a\u003e\n* \u003ca href=\"#get_last_key\"\u003eget_last_key\u003c/a\u003e\n* \u003ca href=\"#get_last_value\"\u003eget_last_value\u003c/a\u003e\n* \u003ca href=\"#array_unset\"\u003earray_unset\u003c/a\u003e\n* \u003ca href=\"#array_iunique\"\u003earray_iunique\u003c/a\u003e\n* \u003ca href=\"#get_directory_size\"\u003eget_directory_size\u003c/a\u003e\n* \u003ca href=\"#get_file_name\"\u003eget_file_name\u003c/a\u003e\n* \u003ca href=\"#get_file_extension\"\u003eget_file_extension\u003c/a\u003e\n* \u003ca href=\"#check_file_exists\"\u003echeck_file_exists\u003c/a\u003e\n* \u003ca href=\"#format_bytes\"\u003eformat_bytes\u003c/a\u003e\n* \u003ca href=\"#datetotime\"\u003edatetotime\u003c/a\u003e\n* \u003ca href=\"#is_date\"\u003eis_date\u003c/a\u003e\n* \u003ca href=\"#t2d\"\u003et2d\u003c/a\u003e\n* \u003ca href=\"#t2dt\"\u003et2dt\u003c/a\u003e\n* \u003ca href=\"#get_range\"\u003eget_range\u003c/a\u003e\n* \u003ca href=\"#_humanize\"\u003e_humanize\u003c/a\u003e\n* \u003ca href=\"#get_class_constant\"\u003eget_class_constant\u003c/a\u003e\n* \u003ca href=\"#get_class_constants\"\u003eget_class_constants\u003c/a\u003e\n* \u003ca href=\"#shorten\"\u003eshorten\u003c/a\u003e\n* \u003ca href=\"#safe_json_encode\"\u003esafe_json_encode\u003c/a\u003e\n* \u003ca href=\"#get_client_ip\"\u003eget_client_ip\u003c/a\u003e\n* \u003ca href=\"#rm_rf\"\u003erm_rf\u003c/a\u003e\n* \u003ca href=\"#copy_r\"\u003ecopy_r\u003c/a\u003e\n* \u003ca href=\"#get_query_params\"\u003eget_query_params\u003c/a\u003e\n* \u003ca href=\"#get_class_name\"\u003eget_class_name\u003c/a\u003e\n* \u003ca href=\"#extract_number\"\u003eextract_number\u003c/a\u003e\n* \u003ca href=\"#seconds_to_hour_minute\"\u003eseconds_to_hour_minute\u003c/a\u003e\n* \u003ca href=\"#is_cli\"\u003eis_cli\u003c/a\u003e\n\n\n### \u003ca id=\"dbg\"\u003e\u003c/a\u003edbg\n```\n/**\n * debug method from Cakephp - convenient wrapper for print_r\n *\n * @param $var\n * @param bool|false $return\n * @return string\n */\nfunction dbg($var, $return = false)\n```\n\n### \u003ca id=\"h\"\u003e\u003c/a\u003eh\n```\n/**\n * Convenience method for htmlspecialchars.\n *\n * @param string|array|object $text Text to wrap through htmlspecialchars. Also works with arrays, and objects.\n *    Arrays will be mapped and have all their elements escaped. Objects will be string cast if they\n *    implement a `__toString` method. Otherwise the class name will be used.\n * @param bool $double Encode existing html entities.\n * @param string|null $charset Character set to use when escaping. Defaults to config value in `mb_internal_encoding()`\n * or 'UTF-8'.\n * @return string Wrapped text.\n * @link http://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#h\n */\nfunction h($text, $double = true, $charset = null)\n```\n\n\n### \u003ca id=\"is_natural\"\u003e\u003c/a\u003eis_natural\n\n```\n/**\n * checks if the given number is a natural number\n *\n * @param int|float|array $number\n * @param bool $zero - if set to true zero will be considered\n * @return bool\n */\nfunction is_natural($number, $zero = false)\n```\n\n### \u003ca id=\"between\"\u003e\u003c/a\u003e between\n\n```\n/**\n * checks if the given value is between 2 values(inclusive)\n *\n * @param int $number\n * @param int $min\n * @param int $max\n * @return bool\n */\nfunction between($number, $min, $max)\n```\n\n### \u003ca id=\"is_numeric_list\"\u003e\u003c/a\u003eis_numeric_list\n```\n/**\n * if an array is provided checks the values of the array all to be numeric,\n * if string is provided, will check to be comma separated list\n *\n * @param mixed $data - array of numbers or string as comma separated numbers\n * @return bool\n */\nfunction is_numeric_list($data)\n```\n\n### \u003ca id=\"last_chars\"\u003e\u003c/a\u003elast_chars\n```\n/**\n * returns given amount of characters counting backwards\n *\n * @param string $str\n * @param int $count\n * @return string\n */\nfunction last_chars($str, $count = 1)\n```\n\n\n### \u003ca id=\"create_slug\"\u003e\u003c/a\u003ecreate_slug\n```\n/**\n * create slug from string\n *\n * @param string $str\n * @param string $symbol\n * @return string - e.g. in word1-word2-word3 format\n */\nfunction create_slug($str = \"\", $symbol = \"-\")\n```\n\n### \u003ca id=\"coalesce\"\u003e\u003c/a\u003ecoalesce\n```\n/**\n * mysql coalesce equivalent\n *\n * @param mixed - list of arguments\n * @return mixed\n * @link http://stackoverflow.com/a/4688108/932473\n */\nfunction coalesce()\n```\n\n### \u003ca id=\"get_first_key\"\u003e\u003c/a\u003eget_first_key\n```\n/**\n * returns the first key of the array\n *\n * @param array $array\n * @return mixed\n */\nfunction get_first_key(array $array = [])\n```\n\n\n### \u003ca id=\"get_first_value\"\u003e\u003c/a\u003eget_first_value\n```\n/**\n * returns the first value of the array\n *\n * @param array $array\n * @return mixed\n */\nfunction get_first_value($array)\n```\n\n\n### \u003ca id=\"get_last_key\"\u003e\u003c/a\u003eget_last_key\n```\n/**\n * returns the last key of the array\n *\n * @param array $array\n * @return mixed\n */\nfunction get_last_key($array)\n```\n\n### \u003ca id=\"get_last_value\"\u003e\u003c/a\u003eget_last_value\n```\n/**\n * returns the last value of the array\n *\n * @param array $array\n * @return mixed\n */\nfunction get_last_value($array)\n```\n\n### \u003ca id=\"array_unset\"\u003e\u003c/a\u003earray_unset\n```\n/**\n * unsets array's items by value\n *\n * @param array $array - the original array\n * @param array|string - the value or array of values to be unset\n * @return array - the processed array\n */\nfunction array_unset($array, $values = [])\n```\n\n\n### \u003ca id=\"array_iunique\"\u003e\u003c/a\u003earray_iunique\n```\n/**\n * case-insensitive array_unique\n *\n * @param array\n * @return array\n * @link http://stackoverflow.com/a/2276400/932473\n */\nfunction array_iunique($array)\n```\n\n\n\n### \u003ca id=\"get_directory_size\"\u003e\u003c/a\u003eget_directory_size\n```\n/**\n * returns the size of the directory\n *\n * @param null $path\n * @param bool|false $unit\n * @param bool|false $intOnly\n * @return string\n * @throws Exception\n * @link http://stackoverflow.com/a/478161/932473\n */\nfunction get_directory_size($path = null, $unit = false, $intOnly = false)\n```\n\n### \u003ca id=\"get_file_name\"\u003e\u003c/a\u003eget_file_name\n```\n/**\n * returns the file name without the extension\n *\n * @param string $fileName\n * @return string\n */\nfunction get_file_name($fileName = '')\n```\n\n### \u003ca id=\"get_file_extension\"\u003e\u003c/a\u003eget_file_extension\n```\n/**\n * returns the file extension from full file name\n *\n * @param string $fileName\n * @return string\n */\nfunction get_file_extension($fileName)\n```\n\n### \u003ca id=\"check_file_exists\"\u003e\u003c/a\u003echeck_file_exists\n```\n/**\n * if file exists will return it - with number concatenated\n *\n * @param $path\n * @param $fileName\n * @param int $n\n * @return bool|string\n */\nfunction check_file_exists($path, $fileName, $n = 100)\n```\n\n\n### \u003ca id=\"format_bytes\"\u003e\u003c/a\u003eformat_bytes\n```\n/**\n * @param $bytes\n * @param int $precision\n * @return string\n * @link http://stackoverflow.com/a/2510459/932473\n */\nfunction format_bytes($bytes, $precision = 0)\n```\n\n### \u003ca id=\"datetotime\"\u003e\u003c/a\u003edatetotime\n```\n/**\n * return timestamp from date considering \"/\" delimiter\n *\n * @return string\n */\nfunction datetotime($date)\n```\n\n\n### \u003ca id=\"is_date\"\u003e\u003c/a\u003eis_date\n```\n/**\n * checks if the given date(s) are valid mysql dates\n *\n * @param null $date1\n * @param null $date\n * @return bool - true if all dates are valid, false otherwise\n */\nfunction is_date($date1 = null, $date = null)\n```\n\n\n### \u003ca id=\"t2d\"\u003e\u003c/a\u003et2d\n```\n/**\n * returns date in Y-m-d format from seconds\n *\n * @param time $timeStr\n * @return date\n */\nfunction t2d($timeStr = null)\n```\n\n### \u003ca id=\"t2dt\"\u003e\u003c/a\u003et2dt\n```\n/**\n * returns date in Y-m-d H:i:s format from seconds\n *\n * @param time $timeStr\n * @return datetime\n */\nfunction t2dt($timeStr = null)\n```\n\n### \u003ca id=\"get_range\"\u003e\u003c/a\u003eget_range\n```\n/**\n * returns array with options for select box\n *\n * @param $min\n * @param $max\n * @param int $step\n * @return array\n */\nfunction get_range($min, $max, $step = 1)\n```\n\n### \u003ca id=\"_humanize\"\u003e\u003c/a\u003e_humanize\n```\n/**\n * @param $val\n * @return string\n */\nfunction _humanize($val)\n```\n\n\n### \u003ca id=\"get_class_constant\"\u003e\u003c/a\u003eget_class_constant\n```\n/**\n * returns constant of the class based on its value\n *\n * @param $className\n * @param $value\n * @param bool|true $humanize\n * @return string\n * @throws Exception\n */\nfunction get_class_constant($className, $value, $humanize = true)\n```\n\n\n### \u003ca id=\"get_class_constants\"\u003e\u003c/a\u003eget_class_constants\n```\n/**\n * returns the list of constants of the given class\n *\n * @param $className\n * @param bool|false $reverse\n * @param bool|true $humanize\n * @return array\n * @throws Exception\n */\nfunction get_class_constants($className, $reverse = false, $humanize = true)\n```\n\n### \u003ca id=\"shorten\"\u003e\u003c/a\u003eshorten\n```\n/**\n * returns the short string based on $length if string's length is more than $length\n *\n * @param string $str\n * @param number $length\n * @param bool $raw\n * @return string\n */\nfunction shorten($str = '', $length = null, $raw = false)\n```\n\n\n### \u003ca id=\"safe_json_encode\"\u003e\u003c/a\u003esafe_json_encode\n```\n/**\n * safe json_encode\n *\n * @param string $value\n * @return string\n */\nfunction safe_json_encode($value)\n```\n\n\n### \u003ca id=\"get_client_ip\"\u003e\u003c/a\u003eget_client_ip\n```\n/**\n * get client ip\n *\n * @return string\n */\nfunction get_client_ip()\n```\n\n### \u003ca id=\"rm_rf\"\u003e\u003c/a\u003erm_rf\n```\n/**\n * linux \"rm -rf\" command equivalent\n * recursively deletes directory\n *\n * @param string $path\n * @throws Exception\n * @return bool\n */\nfunction rm_rf($path)\n```\n\n\n### \u003ca id=\"copy_r\"\u003e\u003c/a\u003ecopy_r\n```\n/**\n * recursively copies files and directories\n *\n * @param string $src\n * @param string $dst\n * @return bool\n */\nfunction copy_r($src, $dst)\n```\n\n\n### \u003ca id=\"get_query_params\"\u003e\u003c/a\u003eget_query_params\n```\n/**\n * parses the url and returns the specified or all list of params\n *\n * @access public\n * @param string $url\n * @param bool $onlyQuery - if true the param will be checked only in the query string, default - false\n * @return mixed - string if found the param, bool false otherwise\n */\nfunction get_query_params($url, $param = '', $onlyQuery = false)\n```\n\n\n### \u003ca id=\"get_class_name\"\u003e\u003c/a\u003eget_class_name\n```\n/**\n * returns class name from object - without namespace\n *\n * @param string $object\n * @return mixed\n */\nfunction get_class_name($object = '')\n```\n\n### \u003ca id=\"extract_number\"\u003e\u003c/a\u003eextract_number\n```\n/**\n * returns numbers from the string\n *\n * @param string $str\n * @return string\n */\nfunction extract_number($str = '')\n```\n\n### \u003ca id=\"seconds_to_hour_minute\"\u003e\u003c/a\u003eseconds_to_hour_minute\n```\n/**\n * converts given seconds to hours and minutes\n *\n * @param null $seconds\n * @return string\n */\nfunction seconds_to_hour_minute($seconds = null)\n```\n\n\n### \u003ca id=\"is_cli\"\u003e\u003c/a\u003eis_cli\n```\n/**\n * check if the current request is from CLI\n *\n * @return bool\n */\nfunction is_cli()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomnicode%2Fphp-util","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fomnicode%2Fphp-util","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomnicode%2Fphp-util/lists"}