Skip to content

Instantly share code, notes, and snippets.

@AlexH-HankIT
AlexH-HankIT / create_zip.php
Created August 17, 2015 01:02
Create zip file
/* creates a compressed zip file */
// @link http://webdeveloperplus.com/php/21-really-useful-handy-php-code-snippets/
function create_zip($files = array(),$destination = '',$overwrite = false) {
//if the zip file already exists and overwrite is false, return false
if(file_exists($destination) && !$overwrite) { return false; }
//vars
$valid_files = array();
//if files were passed in...
if(is_array($files)) {
//cycle through each file
@AlexH-HankIT
AlexH-HankIT / destroyDir.php
Created August 17, 2015 01:01
Delete a directory and its content
/*****
*@dir - Directory to destroy
*@virtual[optional]- whether a virtual directory
*@link http://webdeveloperplus.com/php/21-really-useful-handy-php-code-snippets/
*/
function destroyDir($dir, $virtual = false)
{
$ds = DIRECTORY_SEPARATOR;
$dir = $virtual ? realpath($dir) : $dir;
$dir = substr($dir, -1) == $ds ? substr($dir, 0, -1) : $dir;
@AlexH-HankIT
AlexH-HankIT / array_flatten.php
Last active August 29, 2015 14:27
Create array from multidimensional one
/**
* Create a "normal" array from a multidimensional one
*
* @param array $array multidimensional array to convert
* @return array
* @link http://stackoverflow.com/questions/6785355/convert-multidimensional-array-into-single-array/6785366#6785366
*
*/
public function array_flatten(array $array) {
if (!is_array($array)) {
@AlexH-HankIT
AlexH-HankIT / mempty.php
Created August 17, 2015 00:58
empty function for multiple values
/**
*
* empty() function for multiple values
*
* @link http://stackoverflow.com/questions/4993104/using-ifempty-with-multiple-variables-not-in-an-array
* @return bool
*
*/
public function mempty() {
foreach (func_get_args() as $arg)
@AlexH-HankIT
AlexH-HankIT / recursive_array_search.php
Created August 17, 2015 00:57
array_search for multidimensional arrays
/**
* array_search for multidimensional arrays
*
* @param string $needle
* @param array $haystack
* @return int|bool
*
*/
public function recursive_array_search($needle, array $haystack) {
foreach ($haystack as $key => $value) {
@AlexH-HankIT
AlexH-HankIT / array_find.php
Last active August 29, 2015 14:27 — forked from branneman/gist:951847
array_find() - A case insensitive array_search() with partial matches
<?php
/**
* Case in-sensitive array_search() with partial matches
*
* @param string $needle The string to search for.
* @param array $haystack The array to search in.
*
* @author Bran van der Meer <[email protected]>
* @since 29-01-2010
*/
@AlexH-HankIT
AlexH-HankIT / check_ajax_request.php
Created August 17, 2015 00:51
Function to check if an incoming request is an ajax
/**
* Checks if an incoming request is an ajax
*
* @return bool
*/
public function IsXHttpRequest() {
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
return true;
} else {
return false;