Skip to content

Instantly share code, notes, and snippets.

View mrsize's full-sized avatar

Thomas Dufranne mrsize

View GitHub Profile
@Clorith
Clorith / functions.php
Last active April 9, 2024 01:35
WordPress filter for adding responsive wrapper to embedded content
<?php
/**
* Filter for adding wrappers around embedded objects
*/
function responsive_embeds( $content ) {
$content = preg_replace( "/<object/Si", '<div class="embed-container"><object', $content );
$content = preg_replace( "/<\/object>/Si", '</object></div>', $content );
/**
* Added iframe filtering, iframes are bad.
@luckyshot
luckyshot / readability.css
Last active May 8, 2017 19:50
Typography readability optimization & weight info
/*
100 = thin
200 = extra-light
300 = light
400 = normal, book
500 = medium
600 = demi-bold
700 = bold
800 = heavy
900 = black
@james2doyle
james2doyle / slugify.php
Last active January 12, 2022 13:19
Simple slugify function for PHP. Creates a slug for the passed string, taking into account international characters as well.
<?php
function slugify($string, $replace = array(), $delimiter = '-') {
// https://github.com/phalcon/incubator/blob/master/Library/Phalcon/Utils/Slug.php
if (!extension_loaded('iconv')) {
throw new Exception('iconv module not loaded');
}
// Save the old locale and set the new locale to UTF-8
$oldLocale = setlocale(LC_ALL, '0');
setlocale(LC_ALL, 'en_US.UTF-8');
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
@dlucian
dlucian / Timezone-Select-Template.html
Created June 10, 2013 20:32
Timezone generated HTML output by the Timezone PHP Generator: https://github.com/dlucian/Timezone-Generator-PHP
<select name="timezone" id="timezone">
<optgroup label="UTC -11:00">
<option value="Pacific/Midway">UTC -11:00 Midway</option>
<option value="Pacific/Niue">UTC -11:00 Niue</option>
<option value="Pacific/Pago_Pago">UTC -11:00 Pago_Pago</option>
</optgroup>
<optgroup label="UTC -10:00">
<option value="America/Adak">UTC -10:00 Adak</option>
<option value="Pacific/Honolulu">UTC -10:00 Honolulu</option>
<option value="Pacific/Johnston">UTC -10:00 Johnston</option>
@luckyshot
luckyshot / gist:5395607
Last active May 8, 2017 19:54
Array to CSV spreadsheet
<?php
function encodecsv($string) {
if(strpos($string, ',') !== false || strpos($string, '"') !== false || strpos($string, "\n") !== false) {
$string = '"' . str_replace('"', '""', $string) . '"';
}
return $string;
}
@luckyshot
luckyshot / simpletemplatingengine.php
Last active May 8, 2017 19:54
Simple Templating Engine
<?php
public function view($filename = 'home') {
// Default values for every View
$data = array(
"app_title" => $this->app_title,
"app_tagline" => $this->app_tagline,
"app_url" => $this->app_url,
"app_version" => $this->app_version,
"user_name" => $this->user_name,
);
@luckyshot
luckyshot / response.php
Last active November 1, 2024 08:20
Web scraping done right (with cUrl and user agent)
<?php return array (
'url' => 'https://xaviesteve.com/',
'content' => '<!doctype html><html>...</html>',
'cookies' => '__cfduid=d3fa669e1069e72c2e47d127ab9b8e11f1465390629',
'http_code' => 200,
'content_type' => 'text/html; charset=UTF-8',
'header_size' => 578,
'request_size' => 229,
'filetime' => -1,
'ssl_verify_result' => 0,
@mburst
mburst / rss_reader.php
Created March 24, 2013 03:58
RSS Feed Reader in PHP
<html>
<head>
<title>RSS Feed Reader</title>
</head>
<body>
<?php
//Feed URLs
$feeds = array(
"http://maxburstein.com/rss",
"http://www.engadget.com/rss.xml",
@idev247
idev247 / php-tricks.php
Created February 28, 2013 23:18
Various PHP tricks: - Array - Find previous array element
<?php
/**
* Array: Find previous element (method 1)
* @source http://stackoverflow.com/questions/4792673/php-get-previous-array-element-knowing-current-array-key
*/
$array = array(
12 => array('a','b'),
34 => array('c','d'),
56 => array('e','f')
@idea34
idea34 / useful.php
Created December 10, 2012 16:10
useful php items
<?php // Collection of useful php snippets
// html readable print_r for arrays
echo '<pre>';
print_r($myarray);
echo '</pre>';
?>