Code:
function prev($fallback) {
$previous = "javascript:history.go(-1)";
if(isset($_SERVER['HTTP_REFERER'])) {
return $previous;
} else {
return $fallback;
}
}
Usage: prev("index.php");
Explanation: Sees if there is a previous page value set, if so, return link to previous page, otherwise returns fallback link
Code:
function euro($amount) {
$formatter = new NumberFormatter('nl_NL', NumberFormatter::CURRENCY);
return $formatter->formatCurrency($amount, 'EUR');
}
Usage: euro(100000);
Explanation: Returns euro value (€ 100.000,00)
Code:
function fileExtension($file) {
$ext = pathinfo($file, PATHINFO_EXTENSION);
return $ext;
}
Usage: fileExtension("image.png");
Explanation: Returns the extension of any file with a set extension
Code:
function msg($key, $msg) {
switch($key) {
case "s":
$icon = "check";
$smsg = "Success";
$flag = "success";
break;
case "w":
$icon = "exclamation-triangle";
$smsg = "Warning";
$flag = "warning";
break;
case "d":
$icon = "times";
$smsg = "Error:";
$flag = "danger";
break;
case "i":
$icon = "info";
$smsg = "Information:";
$flag = "info";
break;
default:
$icon = "times";
$flag = "danger";
$smsg = "Unknown error:";
break;
}
echo '<div class="alert alert-'.$flag.' text-center"><b><i class="fa fa-'.$icon.'"></i> '.$smsg.'</b><br />'.$msg.'</div>';
}
Usage: Switches between alerts tag, error message, and icon: msg("tag", "message");
Explanation: Extremely convenient and easy to use when you wish to have simple alerts like these:
Requirement: Bootstrap style library and FontAwesome
If you like these, i'll release more
I know they're easy to write, but incredibly convenient