Monthly Archives: April 2011

Show Bytes

Haven’t actually used this one, but it does work…

 1099511627776,  // pow( 1024, 4)
		'GB' => 1073741824,     // pow( 1024, 3)
		'MB' => 1048576,        // pow( 1024, 2)
		'kB' => 1024,           // pow( 1024, 1)
		'B ' => 1,              // pow( 1024, 0)
	);

	foreach ( $quant as $unit => $mag )
		if ( doubleval($bytes) >= $mag )
			return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit;

	return false;
}
?>

PHP file extension

Never used ‘pathinfo’ before, but I can see its uses..
Personally, I would explode on the ‘/’, then on the ‘.’, etc…

Dump variables

This is my extension of an existing function, adatped for my requirements.

";
    $output .= "";
    $output .= "";
    $output .= "" . $VARIABLE_NAME . "";
    $output .= "";
    $output .= "";
    if (is_array($data)){
        foreach ($data as $key => $value) {
            //$value = dumpr($key, $value);
            $output .= "";
            $output .= "$key";
            $output .= "$value";
            $output .= "";
        }
    } else {
        $output .= "";
        $output .= "$data";
        $output .= "";
    }
    $output .= "";
    $output .= "";
    return $output;
}
?>

Use like this:
echo dumpr(‘NAME’,$var);
echo dumpr(‘SESSION’,$_SESSION);
etc..

Displays a nicely formatted table, with values of a string / array / object clearly displayed.

CSS Reset

/*
 * CSS Reset based on code from 
 * 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,
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-weight: inherit;
	font-style: inherit;
	font-size: 100%;
	font-family: inherit;
	vertical-align: baseline;
}
/* remember to define focus styles! */
:focus {
	outline: 0;
}
body {
	line-height: 1;
	color: black;
	background: white;
}
ol, ul {
	list-style: none;
}
/* tables still need 'cellspacing="0"' in the markup */
table {
	border-collapse: separate;
	border-spacing: 0;
}
caption, th, td {
	text-align: left;
	font-weight: normal;
}
blockquote:before, blockquote:after,
q:before, q:after {
	content: "";
}
blockquote, q {
	quotes: "" "";
}