Skip to content

Instantly share code, notes, and snippets.

View jefferyrdavis's full-sized avatar

jeffery Davis jefferyrdavis

View GitHub Profile
@jefferyrdavis
jefferyrdavis / gist:5992262
Last active December 19, 2015 17:38
Snippit: PHP: Find the extenstion of a filename
<?php
// used to find the extenstion of a filename
function findExtension ($filename) {
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}
?>
@jefferyrdavis
jefferyrdavis / gist:5992271
Last active December 4, 2020 07:16
Snippit: PHP: Format 10 or 7 digit phone number
<?php
/* formats a 10 or 7 digit phone number (number only) by adding dashes at the appropriate locations */
function phoneFormat($number) {
if(ctype_digit($number) && strlen($number) == 10) {
$number = substr($number, 0, 3) .'-'. substr($number, 3, 3) .'-'. substr($number, 6);
} else {
if(ctype_digit($number) && strlen($number) == 7) {
$number = substr($number, 0, 3) .'-'. substr($number, 3, 4);
}
@jefferyrdavis
jefferyrdavis / gist:5992275
Last active December 19, 2015 17:38
Snippit: PHP: Random String Function
<?php
/* Generates a random string from the charachters listed in $characters and returns the random string.
*/
function genRandomString($length) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyz!@#$%&*()';
$randstring = "";
for ($p = 0; $p < $length; $p++) {
$randstring .= $characters[mt_rand(0, strlen($characters))];
}
return $randstring;
@jefferyrdavis
jefferyrdavis / gist:5992282
Last active January 21, 2020 08:55
Snippit: PHP: Simple US Zip Code format validation
<?php
/* Validates if $zipCode is a 5 digit number in the 12345 format. Note that this simply checks to see if $zipCode is a 5 digit number, not necessarily a valid U.S. Zip Code.
*/
function validateZipCode($zipCode) {
if (preg_match('#[0-9]{5}#', $zipCode))
return true;
else
return false;
}
?>
@jefferyrdavis
jefferyrdavis / gist:5992287
Last active May 16, 2019 06:48
Snippit: PHP: Validate U.S. phone Number
<?php
/*Validates if $phone is a valid U.S. phone number in the 202-555-1234 format.
Note that the first didgit cannot be a 1 as no area code in the U.S. starts with a 1.
*/
function validatePhoneNo($phone) {
if(preg_match("/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i", $phone))
return true;
else
return false;
}
@jefferyrdavis
jefferyrdavis / gist:5992291
Last active December 19, 2015 17:38
Snippit: PHP: Target current page (Self-target)
<?php echo $_SERVER['PHP_SELF']; ?>
$lightgray : #819090;
$gray : #708284;
$mediumgray : #536870;
$darkgray : #475B62;
$darkblue : #0A2933;
$darkerblue : #042029;
$paleryellow : #FCF4DC;
$paleyellow : #EAE3CB;
$yellow : #A57706;
$orange : #BD3613;