source: temp/trunk/data/lib/glib.php @ 1328

Revision 1328, 5.8 KB checked in by naka, 20 years ago (diff)

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2
3/*----------------------------------------------------------------------
4 * [̾¾Î] gfDownloadCsv
5 * [³µÍ×] °ú¿ô¥Ç¡¼¥¿¤òCSV¤È¤·¤Æ¡¢¥¯¥é¥¤¥¢¥ó¥È¤Ë¥À¥¦¥ó¥í¡¼¥É¤µ¤»¤ë
6 * [°ú¿ô] 1:¥Ø¥Ã¥Àʸ»úÎó 2:CSV¥Ç¡¼¥¿
7 * [ÌáÃÍ] -
8 * [°Í¸] -
9 * [Ãí¼á] °ú¿ô¤Ï£±¡¤£²¤È¤â¥«¥ó¥Þ¶èÀÚ¤ê¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤³¤È
10 *----------------------------------------------------------------------*/
11function gfDownloadCsv($header, $contents){
12   
13    $fiest_name = date("YmdHis") .".csv";
14   
15    /* HTTP¥Ø¥Ã¥À¤Î½ÐÎÏ */
16    Header("Content-disposition: attachment; filename=${fiest_name}");
17    Header("Content-type: application/octet-stream; name=${fiest_name}");
18   
19    $return = $header.$contents;
20    if (mb_detect_encoding($return) == 'EUC-JP'){                       //ʸ»ú¥³¡¼¥ÉÊÑ´¹
21        $return = mb_convert_encoding($return,'SJIS','EUC-JP');
22        $return = str_replace( array( "\r\n", "\r" ), "\n", $return);   // ²þ¹ÔÊýË¡¤ÎÅý°ì
23    }
24    echo $return;
25}
26
27/*----------------------------------------------------------------------
28 * [̾¾Î] gfSetCsv
29 * [³µÍ×] °ú¿ô¤ÎÇÛÎó¤òCSV·Á¼°¤ËÊÑ´¹¤¹¤ë
30 * [°ú¿ô] 1:CSV¤Ë¤¹¤ëÇÛÎó 2:°ú¿ô1¤¬Ï¢ÁÛÇÛÎó»þ¤Îꤍ»ú¤ò»ØÄꤷ¤¿ÇÛÎó
31 * [ÌáÃÍ] CSV¥Ç¡¼¥¿
32 * [°Í¸] -
33 * [Ãí¼á] -
34 *----------------------------------------------------------------------*/
35function gfSetCsv( $array, $arrayIndex = "" ){ 
36    //°ú¿ô$arrayIndex¤Ï¡¢$array¤¬Ï¢ÁÛÇÛÎó¤Î¤È¤­¤Ëꤍ»ú¤ò»ØÄꤷ¤Æ¤ä¤ë¤¿¤á¤Ë»ÈÍѤ¹¤ë
37   
38    $return = "";
39    for ($i=0; $i<count($array); $i++){
40       
41        for ($j=0; $j<count($array[$i]); $j++ ){
42            if ( $j > 0 ) $return .= ",";
43            $return .= "\"";           
44            if ( $arrayIndex ){
45                $return .= mb_ereg_replace("<","¡ã",mb_ereg_replace( "\"","\"\"",$array[$i][$arrayIndex[$j]] )) ."\"";         
46            } else {
47                $return .= mb_ereg_replace("<","¡ã",mb_ereg_replace( "\"","\"\"",$array[$i][$j] )) ."\"";
48            }
49        }
50        $return .= "\n";           
51    }
52   
53    return $return;
54}
55
56/*----------------------------------------------------------------------
57 * [̾¾Î] gfGetAge
58 * [³µÍ×] ÆüÉÕ¤è¤êǯÎð¤ò·×»»¤¹¤ë¡£
59 * [°ú¿ô] 1:ÆüÉÕʸ»úÎó(yyyy/mm/dd¡¢yyyy-mm-dd hh:mm:ssÅù)
60 * [ÌáÃÍ] ǯÎð¤Î¿ôÃÍ
61 * [°Í¸] -
62 * [Ãí¼á] -
63 *----------------------------------------------------------------------*/
64function gfGetAge($dbdate)
65{
66    $ty = date("Y");
67    $tm = date("m");
68    $td = date("d");
69    list($by, $bm, $bd) = split("[-/ ]", $dbdate);
70    $age = $ty - $by;
71    if($tm * 100 + $td < $bm * 100 + $bd) $age--;
72    return $age;
73}
74
75/*----------------------------------------------------------------------
76 * [̾¾Î] gfDebugLog
77 * [³µÍ×] ¥í¥°¥Õ¥¡¥¤¥ë¤ËÊÑ¿ô¤Î¾ÜºÙ¤ò½ÐÎϤ¹¤ë¡£
78 * [°ú¿ô] ÂоݤȤʤëÊÑ¿ô
79 * [ÌáÃÍ] ¤Ê¤·
80 * [°Í¸] gfPrintLog
81 * [Ãí¼á] -
82 *----------------------------------------------------------------------*/
83function gfDebugLog($obj){
84        gfPrintLog("*** start Debug ***");
85        ob_start();
86        print_r($obj);
87        $buffer = ob_get_contents();
88        ob_end_clean();
89        $fp = fopen(LOG_PATH, "a+");
90        fwrite( $fp, $buffer."\n" );
91        fclose( $fp );
92        gfPrintLog("*** end Debug ***");
93}
94
95/*----------------------------------------------------------------------
96 * [̾¾Î] gfPrintLog
97 * [³µÍ×] ¥í¥°¥Õ¥¡¥¤¥ë¤ËÆü»þ¡¢½èÍý¥Õ¥¡¥¤¥ë̾¡¢¥á¥Ã¥»¡¼¥¸¤ò½ÐÎÏ
98 * [°ú¿ô] ɽ¼¨¤·¤¿¤¤¥á¥Ã¥»¡¼¥¸
99 * [ÌáÃÍ] ¤Ê¤·
100 * [°Í¸] ¤Ê¤·
101 * [Ãí¼á] -
102 *----------------------------------------------------------------------*/
103function gfPrintLog($mess, $path = '') {
104    // ÆüÉդμèÆÀ
105    $today = date("Y/m/d H:i:s");
106    // ½ÐÎϥѥ¹¤ÎºîÀ®
107    if ($path == "") {
108        $path = LOG_PATH;
109    }
110   
111    // ¥¨¥¹¥±¡¼¥×¤µ¤ì¤Æ¤¤¤ëʸ»ú¤ò¤â¤È¤ËÌ᤹
112    $trans_tbl = get_html_translation_table (HTML_ENTITIES);
113    $trans_tbl = array_flip ($trans_tbl);
114    $mess = strtr($mess, $trans_tbl);
115   
116    $fp = fopen($path, "a+");
117    if($fp) {
118        fwrite( $fp, $today." [".$_SERVER['PHP_SELF']."] ".$mess." from ". $_SERVER['REMOTE_ADDR']. "\n" );
119        fclose( $fp );
120    }
121}
122
123/*----------------------------------------------------------------------
124 * [̾¾Î] gfMakePassword
125 * [³µÍ×] ¥é¥ó¥À¥à¥Ñ¥¹¥ï¡¼¥ÉÀ¸À®¡Ê±Ñ¿ô»ú¡Ë
126 * [°ú¿ô] ¥Ñ¥¹¥ï¡¼¥É¤Î·å¿ô
127 * [ÌáÃÍ] ¥é¥ó¥À¥àÀ¸À®¤µ¤ì¤¿¥Ñ¥¹¥ï¡¼¥É
128 * [°Í¸] ¤Ê¤·
129 * [Ãí¼á] -
130 *----------------------------------------------------------------------*/
131function gfMakePassword($pwLength) {
132   
133    // Íð¿ôɽ¤Î¥·¡¼¥É¤ò·èÄê
134    srand((double)microtime() * 54234853);
135   
136    // ¥Ñ¥¹¥ï¡¼¥Éʸ»úÎó¤ÎÇÛÎó¤òºîÀ®
137    $character = "abcdefghkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ2345679";
138    $pw = preg_split("//", $character, 0, PREG_SPLIT_NO_EMPTY);
139   
140    $password = "";
141    for($i = 0; $i<$pwLength; $i++ ) {
142        $password .= $pw[array_rand($pw, 1)];
143    }
144
145    return $password;
146}
147
148/*----------------------------------------------------------------------
149 * [̾¾Î] sf_explodeExt
150 * [³µÍ×] ¥Õ¥¡¥¤¥ë¤Î³ÈÄ¥»Ò¼èÆÀ
151 * [°ú¿ô] ¥Õ¥¡¥¤¥ë̾
152 * [ÌáÃÍ] ³ÈÄ¥»Ò
153 * [°Í¸] ¤Ê¤·
154 * [Ãí¼á] -
155 *----------------------------------------------------------------------*/
156function gf_explodeExt($fileName) {
157    $ext1 = explode(".", $fileName);
158    $ext2 = $ext1[count($ext1) - 1];
159    $ext2 = strtolower($ext2);
160    return $ext2;
161}
162
163
164/*----------------------------------------------------------------------------------------------------------------------
165 * [̾¾Î] gfMailHeaderAddr
166 * [³µÍ×] ÆþÎϤµ¤ì¤¿¥á¡¼¥ë¥¢¥É¥ì¥¹¤ò¥á¡¼¥ë´Ø¿ôÍѤΰ¸Àè¤ËÊÑ´¹
167 * [°ú¿ô] ¡Ö¥á¡¼¥ë¥¢¥É¥ì¥¹¡×¤Þ¤¿¤Ï¡Ö̾Á°<¥á¡¼¥ë¥¢¥É¥ì¥¹>¡×¡¢Ê£¿ô¥¢¥É¥ì¥¹»ØÄê»þ¤Ï¥«¥ó¥Þ¶èÀÚ¤ê¤Ç»ØÄꤹ¤ë¡£
168 * [ÌáÃÍ] ¡Ö¥á¡¼¥ë¥¢¥É¥ì¥¹¡×¤Þ¤¿¤Ï¡ÖJIS_MIME¤Ë¥³¡¼¥ÉÊÑ´¹¤·¤¿Ì¾Á° <¥á¡¼¥ë¥¢¥É¥ì¥¹>¡×¡¢Ê£¿ô¥¢¥É¥ì¥¹»ØÄê»þ¤Ï¥«¥ó¥Þ¶èÀÚ¤ê¤ÇÊֵѤ¹¤ë¡£
169 * [°Í¸] ¤Ê¤·
170 * [Ãí¼á] -
171 *----------------------------------------------------------------------------------------------------------------------*/
172
173function gfMailHeaderAddr($str) {
174    $addrs = explode(",", $str); //¥¢¥É¥ì¥¹¤òÇÛÎó¤ËÆþ¤ì¤ë
175    foreach ($addrs as $addr) {
176        if (preg_match("/^(.+)<(.+)>$/", $addr, $matches)) {
177            //°ú¿ô¤¬¡Ö̾Á°<¥á¡¼¥ë¥¢¥É¥ì¥¹>¡×¤Î¾ì¹ç
178            $mailaddrs[] = mb_encode_mimeheader(trim($matches[1]))." <".trim($matches[2]).">";
179        } else {
180            //¥á¡¼¥ë¥¢¥É¥ì¥¹¤Î¤ß¤Î¾ì¹ç
181            $mailaddrs[] =  trim($addr);
182        }
183    }
184    return implode(", ", $mailaddrs); //Ê£¿ô¥¢¥É¥ì¥¹¤Ï¥«¥ó¥Þ¶èÀÚ¤ê¤Ë¤¹¤ë
185}
186
187?>
Note: See TracBrowser for help on using the repository browser.