Skip to content

Instantly share code, notes, and snippets.

View dcblogdev's full-sized avatar

David Carr dcblogdev

View GitHub Profile
@dcblogdev
dcblogdev / gist:4464465
Created January 6, 2013 00:25
HTML Starter document
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="css/styles.css">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
@dcblogdev
dcblogdev / gist:5248025
Last active December 15, 2015 10:49
The snippet below will return the number of week days between 2 dates also exclude any dates in an array such as bank holidays
<?php
function get_working_days($startDate,$endDate){
$holidays = array(
'2013-03-29',
'2013-04-01',
'2013-05-06',
'2013-05-27',
'2013-08-26',
'2013-12-25',
@dcblogdev
dcblogdev / gist:5679793
Last active January 16, 2022 02:52
filter search example
<?php
if(isset($_GET['submit'])){
extract($_POST);
if(!empty($subject)){ $extra.= " AND subject = '$subject'"; }
if(!empty($id)){ $extra.= " AND id = '$id'"; }
if(!empty($FirstName)){ $extra.= " AND FirstName = '$FirstName'"; }
if(!empty($LastName)){ $extra.= " AND LastName = '$LastName'"; }
if(!empty($address)){ $extra.= " AND address = '$address'"; }
@dcblogdev
dcblogdev / gist:5708821
Created June 4, 2013 19:32
detecting and replacing bad words in a string
<?php
$text = 'word1 some more words. word2 and some more words';
$text = preg_replace_callback('!\w+!', 'filter_bad_words', $text);
echo $text;
function filter_bad_words($matches) {
$bad_words = array(
'word1' => 'gosh',
'word2' => 'darn',
@dcblogdev
dcblogdev / gist:5747856
Last active December 18, 2015 07:39
drop down next 3 days of before 8am show only today.
<?php
date_default_timezone_set('Europe/London');
$m= date("m");
$de= date("d");
$y= date("Y");
?>
<select name'dates'>
<?php
@dcblogdev
dcblogdev / gist:5773211
Created June 13, 2013 12:13
Export from MySQL to Excel
<?php
function cleanData($str){
$str = preg_replace("/\t/", "\\t", $str);
$str = preg_replace("/\n/", "\\n", $str);
}
$filename = "export_" . date('Y-m-d-h-i-s') . ".xls";
header("Content-Disposition: attachment; filename=\"$filename\"");
@dcblogdev
dcblogdev / gist:6062192
Created July 23, 2013 13:00
display demo with PDO
<?php
//connection details
$host = 'localhost';
$dbname = 'database name';
$dbusername = 'database username';
$password = 'db password';
//make a connection
$db = new PDO("mysql:$host=;port=8889;$dbname=", $dbusername, $password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
@dcblogdev
dcblogdev / gist:6083302
Created July 25, 2013 20:12
Get long and lat from Google Map API
<?php
$address = "UK+Hull";
$url = "http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false&region=England";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
@dcblogdev
dcblogdev / gist:6174117
Created August 7, 2013 13:38
captcha example
<?php
session_start();
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
function _generateRandom($length=6)
{
@dcblogdev
dcblogdev / gist:6251264
Created August 16, 2013 16:14
explode post example
<?php
//Blackpool North, Bispham, Cleveleys
$parts = explode(",",$_POST['area']);
echo '<pre>';
print_r($parts);
echo '</pre>';
//output: