Re: [請益] 獲得檔案字串的副檔名
方法有很多貼上我之前測試速度的程式碼給您參考
速度上方法一最慢,方法二、三差不多
<?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
討論串 (同標題文章)
完整討論串 (本文為第 3 之 3 篇):
請益
3
5