<?php
function getExt($filename)
{
return strtolower(pathinfo($filename, PATHINFO_EXTENSION));
}
function calc($num1, $num2, $op = '+')
{
if (!is_numeric($num1) || !is_numeric($num2)) {
exit("非法输入...<br/>");
}
switch ($op) {
case '+':
$res = $num1 + $num2;
break;
case '-':
$res = $num1 - $num2;
break;
case '*':
$res = $num1 * $num2;
break;
case '/':
if ($num2 != 0) {
$res = $num1 / $num2;
} else {
exit('0不能当做除数');
}
break;
case '%':
$res = $num1 % $num2;
break;
}
return "{$num1}{$op}{$num2}={$res}";
}
function getDateStr($del1 = '年', $del2 = '月', $del13 = "日")
{
$dayArr = array("一", "二", "三", "四", "五", "六", "日");
$day = date("w");
return date("Y{$del1}m{$del2}d{$del13} 星期") . $dayArr[$day];
}
?>
<?php
require_once 'common.func.php';
echo calc(1, 2);
echo "<br/>";
echo calc(2, 3, '*');
echo "<br/>";
echo calc("1", 2, "-");
echo "<br/>";
echo calc(3, 2, "/");
echo "<br/>";
echo getDateStr();
echo "<br/>";
echo getDateStr("/", "/", null);
echo "<br/>";
echo getDateStr("^_^", "^_^", "^_^");
?>