<?
class useful{
function formatnumber(num){
return number_format(num, 2, ".", ","); function formatstring(string = ""){
string = preg_replace(array("/ /", "/ /"), array(" ", " "), string);
return nl2br(string); function formatcontent(text){
trans = get_html_translation_table(Html_SPECIALCHARS);
trans = array_flip(trans);
text = strtr(text, trans);
//text = str_replace("\n", "<br>", text);
//text = str_replace(" ", " ", text);
return text; function bitsize(num){
if(!preg_match("/^[0-9]+/", num)) return 0;
return num > 1024 ? (num/1024 > 1024 ? round(num/1024/1024, 2)." Mb" : round(num/1024, 2)." Kb") : num." 字節"; function add_s(&array){
foreach(array as key=>value){
if(!is_array(value)){
array[key]=addslashes(value);
}else{
this->add_s(array[key]); } function specialHtml(&array){
if(is_array(array)){//數組處理
foreach(array as key=>value){
if(!is_array(value)){
array[key]=Htmlspecialchars(value);
}else{
this->specialHtml(array[key]); }
}else{
array = Htmlspecialchars(array); }
function msubstr(str, start, len) {
tmpstr = "";
strlen = start + len;
for(i = 0; i < strlen; i++) {
if(ord(substr(str, i, 1)) > 0xa0) {
tmpstr .= substr(str, i, 2);
i++;
} else
tmpstr .= substr(str, i, 1); return tmpstr; function alert_msg(msg, direct = "0"){
switch(direct){
case '0'://提示
script = "";
case '1'://提示刷新返回
script = "location.href=\""._SESSION["HTTP_REFERER"]."\";";
break;
case '2'://提示返回
script = "history.back();";
break;
default://提示轉向指定頁面
script = "location.href=\"".direct."\";"; echo "<script language='Javascript'>window.alert('".msg."');".script."</script>";
exit; function aweek(gdate = "", first = 0){
if(!gdate) gdate = date("Y-m-d");
w = date("w", strtotime(gdate));//取得一周的第幾天,星期天開始0-6
dn = w ? w - first : 6;//要減去的天數
st = date("Y-m-d", strtotime("gdate -".dn." days"));
en = date("Y-m-d", strtotime("st +6 days"));
return array(st, en);//返回開始和結束日期 function checkurl(){ //echo "referer:"._SESSION['HTTP_REFERER'];
if(!isset(_SESSION['HTTP_REFERER'])) {
header("location: index.PHP");
exit; urlar = parse_url(_SESSION['HTTP_REFERER']); if(_SERVER["HTTP_HOST"] != urlar["host"]) {
header("location: index.PHP");
exit; }
function readfiles(file){
tdata = "";
fp = fopen(file, "r"); if(filesize(file) <= 0) return; while(data = fread(fp, filesize(file))){
tdata .= data; fclose(fp);
return tdata; }
?>