2012年7月30日 星期一

PHP匯出Excel可讀的UTF-8編碼CSV檔案

$fp = fopen($file_name);
用fputcsv製作出來的檔案,
編碼為utf-8無BOM,導致用Excel打開會是亂碼,
因此在寫入資料前先寫入utf8的BOM就可以解決!

fwrite($fp, "\xEF\xBB\xBF");//解決utf8檔頭無BOM之問題

2012年7月5日 星期四

curl - Protocol http not supported or disabled in libcurl

錯誤訊息:
Protocol  http not supported or disabled in libcurl

原因:
url字串裡,目幹多放了空格啊= =+

2011年9月5日 星期一

JavaScript的substr和substring的分別

JavaScript的substr和substring的分別:

String.substr(N1,N2) :從指定的位置(N1)截取指定長度(N2)的字串。

String.substring(N1,N2) :從指定的位置(N1)指定的位置(N2)的字串。


PS. javascript的起始位置是0


例:
 var a="654321";
alert(a.substr(1,2)) 結果:54
alert(a.substring(1,2)) 結果:5

轉自:
http://www.wretch.cc/blog/Gourmets/7485191

2011年8月28日 星期日

2011年8月23日 星期二

Datepicker 設定日期選擇範圍

$(function() {
    $(".timepicker").timePicker();
    $(".datepicker").datepicker({
        dateFormat: 'yy-mm-dd',
        changeMonth: true,
        changeYear: true,
        beforeShow: customRange
    });
});
function customRange(input) //設定datepicker的日期範圍
{
return {
         minDate: (input.id == "pre_statistic_end_date" ? $("#pre_statistic_start_date").datepicker("getDate") : null),
         maxDate: (input.id == "pre_statistic_start_date" ? $("#pre_statistic_end_date").datepicker("getDate") : null)
       };
}

http://stackoverflow.com/questions/330737/jquery-datepicker-2-inputs-textboxes-and-restricting-range

2011年6月21日 星期二

php群組函數array_filter妙用-刪除空白傎

定義和用法

array_filter() 函數用回調函數過濾數組中的元素,如果自定義過濾函數返回true,則被操作的數組的當前值就會被包含在返回的結果數組中, 並將結果組成一個新的數組。如果原數組是一個關聯數組,鍵名保持不變。
語法
array_filter(array,function)
參數描述

array 必需。規定輸入的數組。

function 必需。自定義函數的名稱。

例子

"Dog",1=>"Cat",2=>"Horse"); print_r(array_filter($a,"myfunction")); ?>
輸出:
Array ( [2] => Horse )
而如果沒有帶回調函數時會怎麼樣?我們下面看例子:
$arr = array( 0 => '火躍',

1 => false,
2 => 1,
3 => null,
4 => ”,
6 =>'0′
);
print_r(array_filter($arr));
輸出:
Array ( [0] => 火躍[2] => 1 [5] => http://www.huoyue.org )
現在你可能猜到了這個的作用了,就刪除群組中所有相當於false的值!




原文-http://www.huoyue.org/php_array_filter

2011年6月20日 星期一

在不同的地方呼叫UserId

●在action裡 
   $this->getUser()->getUserId();

●在success
   $sf_user->getUserId();

●在form
   sfContext::getInstance()->getUser()->getUserId();