Skip to content

Instantly share code, notes, and snippets.

View tomschlick's full-sized avatar

Tom Schlick tomschlick

View GitHub Profile
@tomschlick
tomschlick / gist:3812085
Created October 1, 2012 14:23
FuelPHP 1.x Composer Support
@tomschlick
tomschlick / gist:1397070
Created November 27, 2011 06:10
Conditional .htpasswd
#allows a single uri through the .htaccess password protection
SetEnvIf Request_URI "/testing_uri$" test_uri
#allows everything if its on a certain host
SetEnvIf HOST "^testing.yoursite.com" testing_url
SetEnvIf HOST "^yoursite.com" live_url
Order Deny,Allow
AuthName "Restricted Area"
AuthType Basic
<?php
$data = array(
array(
'info' => array(
'pet' => array(
'type' => 'dog'
)
),
),
<?php
// Input array
$user = array(
'name' => 'Bob Smith',
'age' => 43,
'address' => array(
'city' => 'Houston',
'state' => 'TX',
@tomschlick
tomschlick / gist:792004
Created January 23, 2011 11:26
This function allows you to sort a php array by subelement values, this should be used in conjunction with the array_element function.
<?php
function array_sort($array, $key, $order = 'asc', $sort_flags = SORT_REGULAR)
{
if( ! is_array($array))
{
return FALSE;
}
foreach($array as $k=>$v)
@tomschlick
tomschlick / gist:791999
Created January 23, 2011 11:23
This function allows you to dive into an array and provide a fallback value in case the element you want does not exist.
<?php
function array_element($array, $key, $default = false)
{
$key = explode('.', $key);
if(count($key) > 1)
{
if ( ! is_array($array) || ! array_key_exists($key[0], $array))
{
return $default;
@tomschlick
tomschlick / gist:781663
Created January 16, 2011 09:06
php ordinal number helper function
function ordinal($n)
{
$ln = (int) substr($n, -1);
$sln = (int) substr($n, -2);
$r = array('st','nd','rd');
$es = (($sln < 11 || $sln > 19) && $ln > 0 && $ln < 4);
return $n . ($es ? $r[$ln - 1] : 'th');
}
function delete_blog_posts($where)
{
$this->db->where($where);
$this->db->delete(‘blog_posts’);
return $this->db->affected_rows();
}
function update_blog_posts($where, $data)
{
$this->db->where($where);
$this->db->update(‘blog_posts’, $data);
return $this->db->affected_rows();
}
function get_blog_post($where)
{
$this->db->where($where);
$query = $this->db->get(‘blog_posts’, 1);
if($query->num_rows() == 1)
{
return $query->row_array();
}
return FALSE;
}