Skip to content

Instantly share code, notes, and snippets.

@cam-gists
cam-gists / email.php
Created August 20, 2012 16:05
PHP: HTML email
<?php
$to = '[email protected]';
$subject = $name . ' is requesting a free delivery';
$body = '<html>
<head>
<title></title>
</head>
<body>
<h1>Title</h1>
<table>
@cam-gists
cam-gists / ellipsis.php
Created August 20, 2012 16:04
PHP: Ellipsis
<?php
function ellipsis($string, $max_length) {
return (strlen($string) > $max_length) ? substr($string,0,strrpos(substr($string, 0, $max_length), ' '))."…" : $string;
}
print ellipsis("All your base are belong to us", 20);
# All your base are…
@cam-gists
cam-gists / copyright.php
Created August 20, 2012 16:03
PHP: Copyright
@cam-gists
cam-gists / ips.php
Created August 20, 2012 16:02
PHP: Block IPs
$ip_address = $_SERVER['REMOTE_ADDR'];
$blocked = array('72.214.3.245_off', '208.113.135.66', '67.130.131.194', '70.179.6.61');
if (in_array($ip_address, $blocked)){
echo "blocked";
}else{
echo "not blocked";
}
@cam-gists
cam-gists / csv.php
Created August 20, 2012 16:02
PHP: Array to CSV
<?php
function generateCsv($data, $delimiter = ',', $enclosure = '"') {
$handle = fopen('php://temp', 'r+');
foreach ($data as $line) {
fputcsv($handle, $line, $delimiter, $enclosure);
}
rewind($handle);
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
@cam-gists
cam-gists / phone.php
Created August 20, 2012 16:01
PHP: US Phone # validation
<?php
// simple phone number
$phone_number_as_integer = preg_replace("/[^0-9]/", "", $phone);
if( !preg_match("/^()?[0-9]{3}[0-9]{3}[0-9]{4}$/i", $phone_number_as_integer) )
{
$phone_error = 'Please enter a valid phone number.';
}
@cam-gists
cam-gists / url.php
Created August 20, 2012 16:01
PHP: Strict URL Validation
<?php
$url = 'http://example.com';
$validation = filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED);
if ( $validation )
{
$output = 'proper URL';
}
else
{
@cam-gists
cam-gists / email.php
Created August 20, 2012 16:00
PHP: Strict Email VAlidation
<?php
/*
Email Address Validation
Check the variable $email is a valid email address.
Usage:
print validate_email("[email protected]");
Or:
$email = "[email protected]";
@cam-gists
cam-gists / cc.php
Created August 20, 2012 15:59
PHP: Credit Card Validation Class
<?php
class CardValidation {
public $valid = false;
public $valid_cc;
public $valid_cc_type_pair;
public $valid_ccv_type_pair;
public $error;
public function validate($cc, $type = false, $ccv = false) {
@cam-gists
cam-gists / mixins.less
Created August 20, 2012 15:57
LESS: Mixins + Reset
.text-shadow(@color: #000, @size: 1px){
text-shadow: @size @size 1px @color;
}/* Eric Meyer's Reset Reloaded *//* http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/ */html, body, div, span, applet, object, iframe,h1, h2, h3, h4, h5, h6, p, blockquote, pre,a, abbr, acronym, address, big, cite, code,del, dfn, em, font, img, ins, kbd, q, s, samp,small, strike, strong, sub, sup, tt, var,b, u, i, center,dl, dt, dd, ol, ul, li,fieldset, form, label, legend,table, caption, tbody, tfoot, thead, tr, th, td {margin: 0;padding: 0;border: 0;outline: 0;font-size: 100%;vertical-align: baseline;background: transparent;}body {line-height: 1;}ol, ul {list-style: none;}blockquote, q {quotes: none;}/* remember to define focus styles! */:focus {outline: 0;}/* remember to highlight inserts somehow! */ins {text-decoration: none;}del {text-decoration: line-through;}/* tables still need 'cellspacing="0"' in the markup */table {border-collapse: collapse;border-spacing: 0;}
.clearfix:after {
visibility: hidd