Skip to content

Instantly share code, notes, and snippets.

View plasticbrain's full-sized avatar

Mike Everhart plasticbrain

View GitHub Profile
@plasticbrain
plasticbrain / gist:3863749
Created October 10, 2012 07:34
PHP: (REGEX/preg_match) check for http(s)://
//--------------------------------------------------------------------------
// See if a url contains http:// or https://
//--------------------------------------------------------------------------
if( !preg_match('/http(s?)\:\/\//i', $url) ) {
// URL does NOT contain http:// or https://
}
@plasticbrain
plasticbrain / gist:3863756
Created October 10, 2012 07:36
PHP: (REGEX/preg_replace) Remove non-numeric characters
//--------------------------------------------------------------------------
// Remove non-numeric characters
//--------------------------------------------------------------------------
$str = preg_replace('/[^0-9]/s', '', $str);
@plasticbrain
plasticbrain / max_upload_size.php
Created October 12, 2012 19:25
PHP: max upload size
<?php
$max_upload_in_mb = min((int)(ini_get('upload_max_filesize')), (int)(ini_get('post_max_size')), (int)(ini_get('memory_limit')));
echo $max_upload_in_mb . 'mb';
?>
@plasticbrain
plasticbrain / gist:3883001
Created October 13, 2012 02:44
PHP: Get the full URL of the current page
function current_page($params=NULL, $no_trailing_slash=TRUE) {
// http(s)://domain.com
$url = @$_SERVER['HTTPS'] == 'on' ? 'https://'. $_SERVER['SERVER_NAME'] : 'http://'.$_SERVER['SERVER_NAME'];
// add the port number, if there is one
if( @$_SERVER['SERVER_PORT'] != "80" && @$_SERVER['SERVER_PORT'] != "443" ) $url .= ':'. @$_SERVER['SERVER_PORT'];
// Append the query string
$url .= $_SERVER['REQUEST_URI'];
@plasticbrain
plasticbrain / gist:3887245
Created October 14, 2012 04:00
PHP: mime types (array format)
<?php
$mime_types = array(
'.3dm' => 'x-world/x-3dmf',
'.3dmf' => 'x-world/x-3dmf',
'.a' => 'application/octet-stream',
'.aab' => 'application/x-authorware-bin',
'.aam' => 'application/x-authorware-map',
'.aas' => 'application/x-authorware-seg',
'.abc' => 'text/vnd.abc',
'.acgi' => 'text/html',
@plasticbrain
plasticbrain / error-reporting.php
Created October 17, 2012 23:20
PHP: Error Reporting
// Report ALL errors, and show them to the user
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Log errors to log file, and do NOT show them to the user
ini_set('log_errors', 1);
ini_set('display_errors', 0);
@plasticbrain
plasticbrain / sections.css
Created October 31, 2012 00:02
Show/Hide page sections (jQuery, CSS, HTML)
div#page-menu {
float: left;
width: 250px;
margin: 0;
}
div#page-menu ul {
border: 2px solid #ccc;
border-top: none;
padding: 0;
@plasticbrain
plasticbrain / gist:4151298
Created November 26, 2012 23:15
HTACCESS: Force www
### Force www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{SERVER_NAME}%{REQUEST_URI} [R=301]
@plasticbrain
plasticbrain / gist:4151302
Created November 26, 2012 23:15
HTACCESS: Force https
### Force https://
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
@plasticbrain
plasticbrain / MySQL - last accessed tables
Created February 1, 2013 21:55
Get the last accessed tables from database
SELECT table_schema AS DatabaseName,
table_name AS TableName,
update_time AS LastAccessTime,
check_time AS LastCheckTime
FROM information_schema.tables
WHERE update_time < 'yyyy-mm-dd'
GROUP BY table_schema
ORDER BY update_time ASC;