Skip to content

Instantly share code, notes, and snippets.

// age range of registrations
public function age_range($start_date, $end_date, $from_age = 0, $to_age = 50, $language = 'english')
{
$start_date = date('Y-m-d', $start_date) . ' 00:00:00';
$end_date = date('Y-m-d ', $end_date) . ' 23:59:59';
if($to_age == FALSE)
{
$sql = 'SELECT COUNT(id) as cnt from users WHERE (created_at BETWEEN ? AND ?) AND timestampdiff(YEAR,birth_date,now()) >= ? AND language = ?';
define('NOW', time());
'created_at' => date('Y-m-d H:i:s'),
// whats the difference?
'created_at' => date('Y-m-d H:i:s', NOW),
<?php
// convert mm-dd-yyyy to yyyy-mm-dd
$date['date_of_birth'] = '12-30-1980';
print date('Y-m-d', strtotime($data['date_of_birth'])); // outputs 1970-01-01
?>
private function compare_data($json_data = false, $table_data = false)
{
if($json_data == false || $table_data == false)
return false;
// total number of events do not match, so there has to be a difference
if(count($json_data) != count($table_data))
return false;
Array
(
[0] => Array
(
[event_id] => 247093
[date_schedule] => 2014-05-14T02:30:00
[city] => San Diego
[venue] => Humphreys Concerts by the Bay
[buy_link] => http://www.axs.com/events/247093/lindsey-stirling-with-dia-frampton-tickets
),
<?php
$search['cat_id'] = array(11, 12, 14);
$sql .= ' AND (' . implode(' OR c.cat_id = ', $search['cat_id']) . ')';
echo $sql;
// ( OR c.cat_id = 11 OR c.cat_id = 12 OR c.cat_id = 14)
<IfModule mod_rewrite.c>
RewriteEngine On
# Removes index.php from ExpressionEngine URLs
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
@bkmorse
bkmorse / gist:9001727
Created February 14, 2014 14:18
twitter has bad characters in twitter messages that will make your MySQL fail, so this cleans it up for an insert.
<?php
//Test string that will blow up MySQL insert: UlQgQFJabm9ydGg6IEhhcHB5IEJpcnRoZGF5IEBkdWNpZG5pIHlvdXIgbXVzaWMgcmVtaW5kcyBtZSBvZiBteSBiZXN0IG1lbW9yaWVzICNORlNNb3ZpZSAjc2F0ZWxsaXRlZmxpZ2h0IPCfjrbwn5KZ8J+agA==
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function remove_non_utf8($string) {
//reject overly long 2 byte sequences, as well as characters above U+10000 and replace with ?
$string = preg_replace('/[\x00-\x08\x10\x0B\x0C\x0E-\x19\x7F]'.
'|[\x00-\x7F][\x80-\xBF]+'.
@bkmorse
bkmorse / gist:8688596
Created January 29, 2014 14:03
crontab -e to run a codeigniter controller method - I'll forget this
0,13,28,43 * * * * php htdocs/index.php social_posts twitter
1,14,29,44 * * * * php htdocs/index.php social_posts instagram
2,15,30,45 * * * * php htdocs/index.php social_posts facebook
<?php
$string = 'food-q-c-1279-303-6.jpg';
$pattern = '\.\w+';
$replacement = '_small$1';
echo preg_replace($pattern, $replacement, $string);
?>