Functions Directory
This directory contains a collection of utility functions organized into various categories based on their functionality. Below is a brief description of each file and its purpose:
Debug Functions
Includes functions to assist with debugging and printing variables.
debugPrint($data): Print a variable in a readable format.
Directory Functions
Provides functions to handle directory operations, such as displaying the directory structure.
displayDirectoryStructure($dir, $prefix = '', $excludeVendor = true): Display a visual representation of a directory structure.
String Functions
Offers a variety of string manipulation functions, including formatting, escaping, and conversion.
nl2brCustom($text): Convert newlines to HTML line breaks.escapeJs($str): Escape single quotes for JavaScript.slugify($str): Generate a URL slug from a string.truncate($str, $length = 100, $append = '...'): Truncate a string to a specified length.startsWith($haystack, $needle): Check if a string starts with a given substring.endsWith($haystack, $needle): Check if a string ends with a given substring.toUpperCase($str): Convert a string to uppercase.toLowerCase($str): Convert a string to lowercase.capitalizeWords($str): Capitalize the first letter of each word in a string.strReplace($search, $replace, $subject): Replace a substring in a string.
Array Functions
Contains functions for working with arrays, such as flattening arrays and removing elements.
isAssocArray(array $array): Check if an array is associative.arrayGet(array $array, $key, $default = null): Get a value from an array or return a default.arrayRandom(array $array): Get a random element from an array.arrayFirst(array $array): Get the first element of an array.arrayLast(array $array): Get the last element of an array.arrayFlatten(array $array): Flatten a multidimensional array.arrayRemove(array &$array, $value): Remove an element from an array by value.inArray($needle, array $haystack): Check if a value is in an array.
Date Functions
Provides functions for date and time manipulation and formatting.
formatDate($date, $format = 'Y-m-d H:i:s'): Format a date to a readable string.timeSince($datetime): Calculate the time since a given date.getCurrentDateTime($format = 'Y-m-d H:i:s'): Get the current date and time.
Random Functions
Includes functions to generate random values such as strings, integers, and UUIDs.
randomString($length = 10): Generate a random string.randomInt($min = 0, $max = 100): Generate a random integer within a range.generateUUID(): Generate a UUID.
Validation Functions
Contains functions for validating data such as emails, phone numbers, and JSON strings.
isValidEmail($email): Check if a string is a valid email.validatePhoneNumber($number): Validate a phone number format.isJson($string): Check if a value is JSON.
File Functions
Provides functions for handling file operations, including reading, writing, and base64 encoding/decoding.
getFileExtension($filename): Get the file extension from a filename.getMimeType($filename): Get the MIME type of a file.base64EncodeFile($file): Base64 encode a file.base64DecodeToFile($base64, $outputFile): Base64 decode to a file.downloadFile($url, $saveTo): Download a file from a URL.createDirectory($path, $permissions = 0755): Create a directory if it doesn't exist.deleteDirectory($path): Delete a directory and its contents.
Format Functions
Includes functions for formatting various data types such as currency, numbers, and arrays to CSV.
formatCurrency($amount, $currency = '$'): Format a number as currency.bytesToHumanReadable($bytes): Convert bytes to a human-readable format.arrayToCsv(array $array): Convert an array to a CSV string.csvToArray($csv): Convert a CSV string to an array.
Other Functions
Contains miscellaneous utility functions that don't fit into other categories.
redirect($url): Redirect to a different URL.sendEmail($to, $subject, $message, $headers = ''): Send a simple email.getClientIp(): Get the client's IP address.getBrowserInfo(): Get the client's browser information.slugify($str): Generate a URL slug from a string.generatePassword($length = 8): Generate a random password.generateUniqueSlug($text, $existingSlugs = []): Create a unique slug for a URL.sanitizeFilename($filename): Convert a string to a safe filename.getCurrentUrl(): Get the current URL.splitString($delimiter, $string): Split a string by a delimiter.joinArray($delimiter, array $array): Join an array into a string with a delimiter.validatePhoneNumber($number): Validate a phone number format.strContains($haystack, $needle): Check if a string contains another string.factorial($number): Calculate the factorial of a number.isEmailDomainValid($email): Check if an email domain is valid.repeatChar($char, $times): Generate a string of repeated characters.