Tag Archives: PHP

prevent caching of files

Version them in their with their timestamp. This way, when they change, the link will change and the browser will reload the sitemap… Otherwise it will be fine to be cached as it wont have changed.




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.