Skip to content

Instantly share code, notes, and snippets.

View dellow's full-sized avatar

Stew Dellow dellow

  • J&S Accessories
  • UK
View GitHub Profile
@dellow
dellow / p.php
Last active August 29, 2015 14:18
Better print_r() for debugging purposes.
/**
* p
* Better print_r() for debugging purposes.
*
* @since 1.0.0
* @version 1.0.0
**/
function p($data){
$debug = debug_backtrace();
@dellow
dellow / array_flatten.php
Last active August 29, 2015 14:18
Flattens any array.
/**
* array_flatten
* Flattens any array.
*
* @since 1.0.0
* @version 1.0.0
**/
function array_flatten($array){
$return = array();
array_walk_recursive($array, function($a) use (&$return) { $return[] = $a; });
@dellow
dellow / in_arrayi.php
Last active August 29, 2015 14:18
Case insensitive in_array().
/**
* in_arrayi
* Case insensitive in_array().
*
* @since 1.0.0
* @version 1.0.0
**/
function in_arrayi($needle, $haystack){
return in_array(strtolower($needle), array_map('strtolower', $haystack));
}
@dellow
dellow / in_arrayr.php
Last active October 5, 2021 10:10
Multi dimensional in_array().
/**
* in_arrayr
* Multi dimensional in_array().
*
* @since 1.0.0
* @version 1.0.0
**/
function in_arrayr($needle, $haystack, $strict = false) {
foreach($haystack as $item){
if(($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_arrayr($needle, $item, $strict))){
@dellow
dellow / array_searchr.php
Last active October 5, 2021 10:13
Multi dimensional array_search().
/**
* array_searchr
* Multi dimensional array_search().
*
* @since 1.0.0
* @version 1.0.0
**/
function array_searchr($id, $array, $key, $return = false, $query = false){
$matches = array();
@dellow
dellow / array_contains.php
Last active September 20, 2022 03:27
Check if string contains word from array.
/**
* array_contains
* Check if string contains word from array.
*
* @since 1.0.0
* @version 1.0.0
**/
function array_contains($str, array $arr){
foreach($arr as $a){
if(stripos($str, $a) !== false) return true;
@dellow
dellow / word_limit.php
Last active August 29, 2015 14:18
Cuts a string by word count.
/**
* word_limit
* Cuts a string by word count.
*
* @since 1.0.0
* @version 1.0.0
**/
function word_limit($string, $limit, $end = '…'){
$words = explode(" ", $string);
@dellow
dellow / extract_youtube_video.php
Last active October 5, 2021 10:09
Extracts a YouTube iframe video from a string.
/**
* extract_youtube_video
* Extracts a YouTube iframe video from a string.
*
* @since 1.0.0
* @version 1.0.0
**/
function extract_youtube_video($string, $decode = true){
// Decode string.
$content = ($decode) ? html_entity_decode($string, ENT_QUOTES, 'utf-8') : $string;
@dellow
dellow / .htaccess
Created August 4, 2015 13:27
Dev images from live domain
# Dev images from live domain.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*\.(gif|jpg|png)) http://livedomain.com/$1 [QSA,R,L]
</IfModule>
@dellow
dellow / musicsorter.sh
Last active September 13, 2016 23:18
Music Files Sorter
#!/bin/bash
#
# musicsorter.sh
#
# About:
# Will sort a directory of music files by recognising the track name and sorting them into directories like Artist > Track Name.ext.
#
# How To Use:
# `bash musicsorter.sh ./path/to/directory`
#