This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Truncate a string to a certain length if necessary, | |
* optionally splitting in the middle of a word, and | |
* appending the $etc string or inserting $etc into the middle. | |
* | |
* @param string $string input string | |
* @param integer $length length of truncated text | |
* @param string $etc end string | |
* @param boolean $break_words truncate at word boundary |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Extracts a substring from a given string, ensuring it does not exceed a maximum length, | |
* and ends at the last occurrence of a non-breaking space character (' ') within the specified range. | |
* | |
* @param string $string The input string to extract the substring from. | |
* @param int $max The maximum length of the substring. | |
* @param int $min The minimum length of the substring before considering the last non-breaking space. | |
* @param string $endstring Optional: The string to append to the extracted substring. | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Validate an email address. | |
* Provide email address (raw input) | |
* Returns 1 if the email address has the email | |
* address format and the domain exists. | |
*/ | |
function validEmail($email) { | |
$isValid = 1; | |
$atIndex = strrpos($email, "@"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Generate random password | |
* @param int $length [optional] [default 9] length password to be generated | |
* @return string | |
* @link http://www.webtoolkit.info/php-random-password-generator.html | |
* @since 12/1/12 11:30 AM | |
*/ | |
function generatePassword($length = 9) { | |
$vowels = 'aeuy'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Efficient PHP Function for Deleting Directories and Their Contents | |
* | |
* This PHP function, named 'deleteDirectory,' is designed to safely and | |
* efficiently delete directories and all their contents. It first checks if | |
* the directory exists, and if not, it returns 'true' since the directory is | |
* already deleted. Next, it determines whether the specified path is a directory | |
* or a symbolic link and unlinks it if necessary. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* IP to long | |
* @param type $ip | |
* @return int | |
*/ | |
function ipToLong($ip = false) { | |
if (!$ip) { | |
$ip = getClientIPAddress(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Retuns client's IP address | |
* @return string | |
* @since 6/16/11 12:11 PM | |
*/ | |
function getClientIPAddress() { | |
if (getenv("HTTP_CLIENT_IP")) { | |
$ip = getenv("HTTP_CLIENT_IP"); | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Detect Mobile Browsers | |
* @link http://detectmobilebrowsers.com/ | |
* @return boolean | |
*/ | |
static function idMobileBrowser() { | |
$useragent = $_SERVER['HTTP_USER_AGENT']; | |
if (preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', | |
$useragent) || preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This function performs an HTTP POST request to a specified URL with given parameters. | |
* | |
* @param string $url The URL to which the POST request is sent. | |
* @param array $params An associative array containing the POST parameters as key-value pairs. | |
* @param string $referer The referer header for the request. | |
* | |
* @return mixed The response from the HTTP POST request. | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Finds whether a variable is a unsigned float or a numeric string. | |
* Sometimes, we need to have no letters in the number and is_numeric does not quit the job. | |
* @param string The variable being evaluated. | |
* @link http://php.net/manual/en/function.is-numeric.php#47491 | |
* @return 1|emptystring It returns 1 if okay and returns nothing "" if it's bad number formating | |
* @since 11/6/14 11:15 AM | |
*/ | |
function isUnsignedFloat($val) { |