{"id":26796428,"url":"https://github.com/peterujah/php-functions","last_synced_at":"2025-03-29T18:18:41.014Z","repository":{"id":45781842,"uuid":"514548595","full_name":"peterujah/php-functions","owner":"peterujah","description":"Wrapped all basic reusable php function which I always on on project","archived":false,"fork":false,"pushed_at":"2022-10-13T08:27:03.000Z","size":166,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-10T01:32:11.077Z","etag":null,"topics":[],"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/peterujah.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":"2022-07-16T10:38:36.000Z","updated_at":"2023-09-24T03:47:48.000Z","dependencies_parsed_at":"2022-09-26T21:30:20.439Z","dependency_job_id":null,"html_url":"https://github.com/peterujah/php-functions","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterujah%2Fphp-functions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterujah%2Fphp-functions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterujah%2Fphp-functions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterujah%2Fphp-functions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peterujah","download_url":"https://codeload.github.com/peterujah/php-functions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246223304,"owners_count":20743168,"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","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":[],"created_at":"2025-03-29T18:18:40.514Z","updated_at":"2025-03-29T18:18:41.008Z","avatar_url":"https://github.com/peterujah.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# php-functions\n\nWrapped all basic reusable php function which is always useful while working on other project.\nThis class might also be useful to beginners\n\nThis class provides general-purpose PHP functions to process several functions, it can perform several types of manipulation of string values and other executions.\n\nCurrently, it can:\n\n- Create a random value string, int, key, salt or letters of a given length\n- Convert timestamp values into a time format for use on social media sites or forum comments\n- Generate and validate a unique identifier string\n- Generate Unified Public Consultation (UPC)\n- Generate European Article Number (EAN) or (EAN13)\n- Genrate Big Integer based on min and max\n- Check if a string is a valid email address\n- Check a password complexity count, using general secure password pattern\n- Encrypt password string to create a hash value\n- Decrypts a password hash and verifies if it matches\n- Calculate a list of item's average rating point\n- Formats a currency value to add decimal places\n- Discount a value by percentage\n- Increase a value by percentage\n- Fixed or Round a number to counts\n- Creates a badge from an array\n- Creates a button badge from an array\n- Gets the current user's IP address\n- Get the list of hours\n- Format the user input to protect again cross site scripting attacks\n- Convert string characters to HTML entities\n- Copy files and folder to a new directory\n- Serve a file for download on the browser\n- Truncate text\n- Base64 encoded string to a parameter in a URL\n- Base64 decode encoded URL encoded string\n- Stripe unwanted characters from a string\n- Extract domain name from subdomain demo.example.com\n- Mask email address\n- Mask string by position\n- Deletes files and folders\n- Write a new log line\n- Save log and replace old content\n- Find the log file\n\n\n\n## Installation\n\nInstallation is super-easy via Composer:\n```md\ncomposer require peterujah/php-functions\n```\n## Usages\n\n```php \nuse \\Peterujah\\NanoBlock\\Functions;\n$func = new Functions();\n```\nOr extend the class and create your own new function like below.\n```php\nclass MyFunction extends \\Peterujah\\NanoBlock\\Functions{\n  public function __construct(){\n  }\n  public function myFunction(){\n    //do anything\n  }\n  public static function myStaticFunction(){\n    //do anything\n  }\n}\n```\nAnd call initialize your custom class\n```php\n$func = new MyFunction();\n```\n\n## Available Static Methods\n\nMake a random string/number\n```php \nFunctions::Random(10, Functions::INT);\n```\nMake a time ago from php timestamp, returns string\n```php \nFunctions::timeSocial(php_timestamp);\n```\nGenerate a uuid string, returns string\n```php \nFunctions::uuid();\n```\n\nVerify a uuid string return true or false\n```php \nFunctions::is_uuid($uuid);\n```\n\nVerify email address is valid or not return true or false\n```php \nFunctions::is_email($email);\n```\n\nCreate a password hash key\n```php \nFunctions::Encrypt($password);\n```\n\nVerify a password against hash key\n```php \nFunctions::Decrypt($password, $hash);\n```\n\nCheck password strength\n```php \nFunctions::strongPassword($password, $minLength = 8,$maxLength = 16, $complexity=4);\n```\n\nExtract main domain name from subdomain\n```php\nFunctions::removeSubdomain(\"subdomain.example.com\"); //returns example.com\n```\n\nCalculate items average rating point\n```php \nFunctions::calcAverageRating($total_user_reviews, $total_rating_count);\n```\nFormat number to money\n```php \nFunctions::Money($number, $fractional);\n```\n\nDiscount from an (int, float, double) value by percentage\n```php \nFunctions::Discount(100, 10); // return 90\n```\n\nIncrease interest of an (int, float, double) value by percentage\n```php \nFunctions::Interest(100, 10); //return 110\n```\n\nFixed/Round a number \n```php \nFunctions::Fixed(12345.728836, 2);\n```\n\nRandome number using min and max\n```php \nFunctions::BigInteger(12345, 728836);\n```\n\nCreate a tag/badge from array\n```php \nFunctions::badges(\n    [\"php\", \"js\", \"css\"], \n    $bootstrap_color_without_prefix, \n    $type_of_badge, \n    $url_prefix_for_links\n);\n```\n\nCreate a button tag/badge from array\n```php \nFunctions::buttonBadges(\n    [\"php\", \"js\", \"css\"], \n    $bootstrap_color_without_prefix, \n    $truncate, \n    $truncate_limit, \n    $selected_button_by_value\n);\n```\n\nReturns user ip address\n```php \nFunctions::IP();\n```\nList time hours, returns array\n```php \nFunctions::hoursRange();\n```\n\nSecure/format user input based on required data type\n```php \nFunctions::XSS(\"Rhd53883773\", \"int\");\n```\n\nFormats Convert string characters to HTML entities\n```php \nFunctions::htmlentities($string, $encode);\n```\n\nGenerate UPC product id\n```php \nFunctions::UPC($prefix = 0, $length = 12);\n```\n\nGenerate EAN13 id\n```php \nFunctions::EAN($country = 615, $length = 13);\n```\n\nCopy files and folder to a new directory\n```php \nFunctions::copyFiles(\"path/from/file/\", \"path/to/file/\");\n```\n\nCopy files and folder to a new directory\n```php \nFunctions::download(\n    \"path/to/download/file.zip\", //string filepath to download\n    \"file.zip\", // string file name to download\n    false // bool delete file after download is complete true or false\n);\n```\n\nTruncate text based on length\n```php \nFunctions::truncate(\n    $text, //string text to truncate\n    $length // int length to display\n);\n```\n\nBase64 encode string for url passing\n```php \nFunctions::base64_url_encode($input);\n```\nBase64 decode encoded url encoded string\n```php \nFunctions::base64_url_decode($encoded_input);\n```\nMask email address\n```php \nFunctions::maskEmail(\n    $email, // string email address\n    \"*\" // character to mask with\n);\n```\n\nMask string by position\n```php \nFunctions::mask(\n    $string, // string to mask\n    \"#\", // character to mask with\n    $position  //string position to mask left|right|center\"\n)\n```\nDetermine password strength, if it meet all basic password rules such as\n1. Does password meet the the minimum and maximum length?\n2. Does password contain numbers?\n3. Does password contain uppercase letters?\n4. Does password contain lowercase letters?\n5. Does password contain special characters?\n\n```php\nFunctions::strongPassword($password, $minLength, $maxLength);\n```\n\nDeletes files and folders\n```php \nFunctions::remove(\n    \"path/to/delete/file/\", // path to delete files\n    false // delete base file once sub files and folders has been deleted\n) \n```\n\nWrite new log line file\n```php \nFunctions::writeLog(\n    \"path/to/logs/\", // string path to save logs\n    \"info.php\",  // string log file name, use .php extension to secure log file from accessible in browser\n    $data, // mixed log content\n    $secure, // bool set true if file is using .php extension security method \n    $serialize, // bool serialize log content\n    $replace // bool replace old log content\n);\n```\nSave log a short hand replace parameter in `Functions::writeLog`\n```php \nFunctions::saveLog(\n    \"path/to/logs/\", // string path to save logs\n    \"info.php\",  // string log file name, use .php extension to secure log file from accessible in browser\n    $data, // mixed log content\n    $secure, // bool set true if file is using .php extension security method \n    $serialize, // bool serialize log content\n);\n```\n\nFind log file\n```php \nFunctions::findLog(\n    \"path/to/logs/info.php\", //string filepath to log\n    $unserialize // bool unserialize content if it was saved in serialize mode\n);\n```\n\nStripes unwanted characters from string and display text in new line in textarea\n```php \n$func-\u003estripeText(\n    $string, // string text to stripe unwanted characters\n    $rules, // array rules array(\"[br/]\" =\u003e  \"\u0026#13;\u0026#10;\",\"\u003cscript\u003e\"    =\u003e \"oops!\",)\n    $textarea // bool display text inside textarea\n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterujah%2Fphp-functions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeterujah%2Fphp-functions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterujah%2Fphp-functions/lists"}