Changeset 21579
- Timestamp:
- 2012/03/03 15:42:05 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_12-dev/data/class/util/GC_Utils.php
r21516 r21579 30 30 */ 31 31 class GC_Utils { 32 33 /*----------------------------------------------------------------------34 * [名称] gfDownloadCsv35 * [概要] 引数データをCSVとして、クライアントにダウンロードさせる36 * [引数] 1:ヘッダ文字列 2:CSVデータ37 * [戻値] -38 * [依存] -39 * [注釈] 引数は1,2ともカンマ区切りになっていること40 *----------------------------------------------------------------------*/41 function gfDownloadCsv($header, $contents) {42 43 $fiest_name = date('YmdHis') .'.csv';44 45 /* HTTPヘッダの出力 */46 Header("Content-disposition: attachment; filename=${fiest_name}");47 Header("Content-type: application/octet-stream; name=${fiest_name}");48 49 $return = $header.$contents;50 if (mb_detect_encoding($return) == CHAR_CODE) {51 // 文字コード変換52 $return = mb_convert_encoding($return,'SJIS',CHAR_CODE);53 // 改行方法の統一54 $return = str_replace( array("\r\n", "\r"), "\n", $return);55 }56 echo $return;57 }58 59 /*----------------------------------------------------------------------60 * [名称] gfSetCsv61 * [概要] 引数の配列をCSV形式に変換する62 * [引数] 1:CSVにする配列 2:引数1が連想配列時の添え字を指定した配列63 * [戻値] CSVデータ64 * [依存] -65 * [注釈] -66 *----------------------------------------------------------------------*/67 function gfSetCsv($array, $arrayIndex = '') {68 //引数$arrayIndexは、$arrayが連想配列のときに添え字を指定してやるために使用する69 70 $return = '';71 for ($i=0; $i<count($array); $i++) {72 73 for ($j=0; $j<count($array[$i]); $j++) {74 if ($j > 0) $return .= ',';75 $return .= "\"";76 if ($arrayIndex) {77 $return .= mb_ereg_replace('<','<',mb_ereg_replace("\"","\"\"",$array[$i][$arrayIndex[$j]])) ."\"";78 } else {79 $return .= mb_ereg_replace('<','<',mb_ereg_replace("\"","\"\"",$array[$i][$j])) ."\"";80 }81 }82 $return .= "\n";83 }84 85 return $return;86 }87 88 /*----------------------------------------------------------------------89 * [名称] gfGetAge90 * [概要] 日付より年齢を計算する。91 * [引数] 1:日付文字列(yyyy/mm/dd、yyyy-mm-dd hh:mm:ss等)92 * [戻値] 年齢の数値93 * [依存] -94 * [注釈] -95 *----------------------------------------------------------------------*/96 function gfGetAge($dbdate) {97 $ty = date('Y');98 $tm = date('m');99 $td = date('d');100 list($by, $bm, $bd) = preg_split('/[-/ ]/', $dbdate);101 $age = $ty - $by;102 if($tm * 100 + $td < $bm * 100 + $bd) $age--;103 return $age;104 }105 32 106 33 /**
Note: See TracChangeset
for help on using the changeset viewer.