PHP 使用 glob 搜尋所有檔案路徑

/**
02.* 在使用之前,我們先大致了解一下glob有什麼特別的參數可以使用。
03.*
04.* GLOB_MARK     - 若檔案為資料夾,在回傳檔案路徑的最後面加上斜線""
05.* GLOB_NOSORT   - 保持檔案路徑在原資料夾的出現順序(不重新排序)。※筆者在Win環境看不出差異
06.* GLOB_NOCHECK  - 若找不到匹配的檔案路徑,回傳匹配的條件字串
07.* GLOB_NOESCAPE - 不要將反斜線視為跳脫字元(※筆者在Win環境下看不出差異)
08.* GLOB_BRACE    - 將 {a,b,c} 視為搜尋 'a', 'b', 或 'c'
09.* GLOB_ONLYDIR  - 只列出資料夾路徑
10.* GLOB_ERR      - 發生讀取錯誤時停止動作(像是無法讀取的資料夾),預設是「忽略錯誤」
11.**/
01.// 搜尋 path 資料夾中,所以資料夾的路徑,並在最後加上斜線 ""
02.$dirs array_filter(glob('/path/*',GLOB_MARK), 'is_dir');
03. 
04.// 同上的結果(所以資料夾的路徑),而且此方法比較標準效能也較快
05.// (※不同這邊要注意的是,GLOB_ONLYDIR 僅適用於非使用 GUN C library 的系統
06.// 所以當不支援的時候,可以改用第一種方法)
07.$dirs glob('/path/*',GLOB_ONLYDIR | GLOB_MARK);
08. 
09.// 搜尋path資料夾中,所有的檔案的路徑
10.// (※筆者很好奇,=3=既然都有 GLOB_ONLYDIR 了,為什麼不多個 GLOB_ONLYFILE )
11.$files array_filter(glob('/path/*'), 'is_file');
12. 
13.// 搜尋 path 資料夾中所有檔名字串結尾為 .gif、.jpg、.png 檔案路徑
14.//(※這邊要注意,若副檔名大小寫不一樣,會搜尋不到,像 .GIF 、 .gIf 或 .giF 都會被忽略掉)
15.$images glob("/path/{*.gif,*.jpg,*.png}", GLOB_BRACE);
16. 
17.// 搜尋 path 資料夾中所有檔名字串結尾非 "_s.jpg" 檔案路徑
18.$filter array_filter(glob('img/*'), function($ele){return !stristr($ele,'_s.jpg');});
19. 
20.// 搜尋 path 中所有含有 views 資料夾的資料夾
21.$dirs glob('/path/*/views', GLOB_ONLYDIR);
22. 
23.//以遞迴的方式,取得深層資料夾的所有路徑
24.function listdirs($dir) {
25.static $alldirs array();
26.$dirs glob($dir '/*', GLOB_ONLYDIR);
27.if (count($dirs) > 0) {
28.foreach ($dirs as $d$alldirs[] = $d;
29.}
30.foreach ($dirs as $dir) listdirs($dir);
31.return $alldirs;
32.}

轉自
http://liaosankai.pixnet.net/blog/post/29021189-%E4%BD%BF%E7%94%A8-glob-%E6%90%9C%E5%B0%8B%E6%89%80%E6%9C%89%E6%AA%94%E6%A1%88%E8%B7%AF%E5%BE%91[……]

閱讀更多

jQuery Selector input type and name 選取器,選取標籤多屬性,如type&name

選取器,選取標籤多屬性,如type&name
可用於選取姓別的radiobox

if(sex==1){
$(“input[name=’sex’][type=’radio’][value=’1′]”).attr(“checked”,true);
}else{
$(“input[name=’sex’][type=’radio’][value=’0′]”).attr(“checked”,true);
}

相關網址
http://stackoverflow.com/questions/3221094/target-input-by-type-and-name-selector[……]

閱讀更多

責任

當所有人都追求正常上下班時~
如果下班就是下班~
那這世界到底有多可怕!!!
當你們在下班的時候~
請慶興有人正還在努力工作著~
這就是責任

2014.8.1 高雄凱旋 丙烯大爆炸[……]

閱讀更多

PHP big5轉utf8不要用iconv(),iconv這個函數,用mb_convert_encoding

不要以為big5轉utf8就用iconv()這麼簡單

big5有很多字是沒有收錄的:

測試:

用法:

原文出自:

http://sweslo17.blogspot.tw/2012/04/big5-erpms-sql-local-cache-phpiconv.htmlhttp://dev.sopili.net/2009/08/phpbig5utf8iconv.htmlhttp://help.i2yes.com/?q=node/65

[……]

閱讀更多

CSS em標籤失效 em,strong,em tag not working

我們習慣在CSS編寫前引入reset.css來重設所有標籤的預設樣式,
但引入reset.css後,透過編輯器如CKEditor,可能產生斜體<em>標籤,
此時<em>標籤便失去原本html應該會呈現的斜體,另外粗體<b>..等,也會有此現象,
解決方法在引入reset.css後加入下面兩行CSS,問題解決
strong, b, strong *, b * { font-weight: bold !important; }
em
, i, em *, i * { font-style: italic !important; }

[……]

閱讀更多

CSS 項目符號

list-style-type:none; 《不編號》
list-style-type:decimal; 《阿拉伯數字》
list-style-type:lower-roman; 《小寫羅馬數字》
list-style-type:upper-roman; 《大寫羅馬數字》
list-style-type:lower-alpha; 《小寫英文字母》
list-style-type:upper-alpha; 《大寫英文字母》
list-style-type:disc; 《實心圓形符號》
list-style-type:circle; 《空心圓形符號》
list-style-type:square; 《實心方形符號》
list-style-image:url(dot.gif); 《圖片式符號》
list-style-position:outside; 《凸排》
list-style-position:inside; 《縮排》

原文出處
http://stenlyho.blogspot.tw/2008/07/css.html

[……]

閱讀更多