Re: [請益] 獲得檔案字串的副檔名

看板PHP作者 (Austin)時間14年前 (2009/09/15 15:06), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串3/3 (看更多)
方法有很多貼上我之前測試速度的程式碼給您參考 速度上方法一最慢,方法二、三差不多 <?php function get_time() { $time = explode( " ", microtime()); $usec = (double)$time[0]; $sec = (double)$time[1]; return $sec + $usec; } // 方法一 $start = get_time(); for($i=0;$i<1000;$i++) { $ext = strtolower(array_pop(explode('.', 'test.inc.php'))); } echo $ext.' '.(get_time() - $start).'<br />'; // 方法二 $start = get_time(); for($i=0;$i<1000;$i++) { $ext = strtolower(substr(strrchr('test.inc.php', "."), 1)); } echo $ext.' '.(get_time() - $start).'<br />'; // 方法三 $start = get_time(); for($i=0;$i<1000;$i++) { $ext = strtolower(substr('test.inc.php' ,strrpos('test.inc.php', '.')+1)); } echo $ext.' '.(get_time() - $start).'<br />'; ?> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.240.3.23

09/15 15:32, , 1F
感謝
09/15 15:32, 1F
文章代碼(AID): #1Ahpq2NQ (PHP)
文章代碼(AID): #1Ahpq2NQ (PHP)