View array_search_recursive.php
# Recursive replacement for in_array() function
function array_search_recursive($needle, $haystack) {
# Validate data types
if (is_array($needle) || !is_array($haystack)) {
return null;
}
# Check if in_array() will suffice
if (in_array($needle, $haystack)) {
View Request.php
<?php
class Request {
/**
* do_post
* POST request
*
* @access public
* @param string $url - url
View rgb2hex.php
<?php
function rgb2hex($r, $g, $b) {
return hexify($r).hexify($g).hexify($b);
}
function hexify($num) {
$num = (int)$num;
$map = '0123456789ABCDEF';
$num = max(0, min($num, 255));
View getNISTbits.php
<?php
function getNISTbits($password, $rules=array()) {
if (empty($rules)) {
$rules['diminishing'] = true;
$rules['upper'] = 2;
$rules['lower'] = 2;
$rules['number'] = 1;
$rules['special'] = 1;
View makeRandom.php
<?php
function makeRandom($length, $special = true) {
$chars = '0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ';
if($special == true) {
$chars .= '!@#$*&%?-_=+^';
}
$string = '';
for($i = 0; $i < $length; $i++) {
$string .= $chars[rand(0, strlen($chars) -1)];
View isUnique.php
<?php
# Pass the mysqli object to the function itself
# $db = new mysqli($host, $user, $pass, $dbname);
function isUnique($db, $table, $col, $data) {
if($db->connect_errno) {
die('Connect Error ('.$db->connect_errno.') '.$db->connect_errno);
}
else {
if($check = $db->query("SELECT ".$col." FROM ".$table." WHERE ".$col."='".$data."'")) {
View validPhone.php
<?php
function validPhone($phone) {
$format_pattern = '/^(?:(?:\((?=\d{3}\)))?(\d{3})(?:(?<=\(\d{3})\))?[\s.\/-]?)?(\d{3})[\s\.\/-]?(\d{4})\s?(?:(?:(?:(?:e|x|ex|ext)\.?\:?|extension\:?)\s?)(?=\d+)(\d+))?$/';
$nanpa_pattern = '/^(?:1)?(?(?!(37|96))[2-9][0-8][0-9](?<!(11)))?[2-9][0-9]{2}(?<!(11))[0-9]{4}(?<!(555(01([0-9][0-9])|1212)))$/';
//Set array of variables to false initially
$valid = array(
'format' => false,
View getTweets.php
<?php
/**
* @param string $user twitter username
* @param integer $count how many tweets to retrieve
* @param bool $wp if using in wp environment, set to true
*
* @return json object retrieved from the twitter API containing
* all tweets matching the passed parameters, or a "fake" tweet
* saying the twitter API is down (if unreachable)
View validEmail.php
<?php
function validEmail($email) {
$isValid = true;
$atIndex = strrpos($email, "@");
if(is_bool($atIndex) && !$atIndex) {
$isValid = false;
}
else {
$domain = substr($email, $atIndex+1);
View convertRelativity.php
<?php
function convertRelativity($tstamp) {
$secs = time() - $tstamp;
$mins = round($secs / 60);
$hrs = round($mins / 60);
$days = round($hrs / 24);
$wks = round($days / 7);