2012年9月25日 星期二

修正郵件標題亂碼



$this->subject = "=?UTF-8?B?" . base64_encode($this->subject) . "?=";
//郵件修正亂碼
就可以正常顯示標題。 不會中斷長標題。

AD 帳戶 到期日 寫入方式(for php)

首先寫入AD 帳戶到期日的欄位是:accountExpires

accountExpires 是以100 nanosecond increment為單位寫入
換算方式如下:



$account_expires_string = (現在的timestamp+ 11644560000) * 10000000;

echo "<br>".$account_expires_string."\n";

$info["accountExpires"] =  account_expires_string  ;

$info["accountExpires"] = 0; =>表示帳號永不到期


2012年9月18日 星期二

php 產生制定格式 日期的做法



產生 一個月之後的日期
echo date_create("+1 month")->format('Y-m-d h:i:s');

產生一天之後的日期
echo date_create("+1 day")->format('Y-m-d h:i:s');

2012年9月5日 星期三

遇PHPEXCEL輸出會有亂碼


在header()之前加上
ob_end_clean();
就這麼一句,亂碼解決了!

PHPEXCEL 讀取excel ,寫入excel

1、include 這三隻
require_once(PHPExcel.php") ;
require_once(PHPExcel/IOFactory.php") ;
require_once(PHPExcel/Reader/Excel5.php") ;


讀取的部分
2、for2003前的版本
$reader = PHPExcel_IOFactory::createReader('Excel5');
$PHPExcel = $reader->load('2012_09_05_member.xls'); // 檔案名稱 需與執行的程式放在同一目錄
$sheet = $PHPExcel->getSheet(0); // 讀取第一個工作表(編號從 0 開始)
$highestRow = $sheet->getHighestRow(); // 取得總列數


$i =0;
// 一次讀取一列
for ($row = 2; $row <= $highestRow; $row++) {
for ($column = 0; $column <= 7; $column++) {
$val = $sheet->getCellByColumnAndRow($column, $row)->getValue();
// echo $val . '';
}
$i++;
// echo "<br />";
}

寫入的部份:
3、

$PHPExcel->setActiveSheetIndex(0);
$l=0;
 for ($k = 0; $k < count($member) ; $k++) {
$PHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8,($k+2) ,$member[$l][8]);
  $l++;
 }


4、輸出的部份

$PHPExcelWriter = PHPExcel_IOFactory::createWriter($PHPExcel, 'Excel5');
$PHPExcelWriter->save('檔名');
ob_end_clean();
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename= 檔名 ");
header("Content-Length: ".filesize(' 檔名 '));
@readfile(' 檔名 ');