分析web项目开发常用代码片段

0
CSS Web开发 C/C++ Go 12573 次浏览
今天给大家分享一些我用过的web开发代码片段,希望与开发者们互相学习交流
计算执行时间
//Create a variable for start time  
$time_start = microtime(true);  
// Place your PHP/HTML/JavaScript/CSS/Etc. Here  
//Create a variable for end time  
$time_end = microtime(true);  
//Subtract the two times to get seconds  
$time = $time_end - $time_start;  
echo 'Script took '.$time.' seconds to execute'; 

关键词高亮
function highlight($sString, $aWords) {  
    if (!is_array ($aWords) || emptyempty ($aWords) || !is_string ($sString)) {  
        return false;  
    }  
 
    $sWords = implode ('|', $aWords);  
    return preg_replace ('@\b('.$sWords.')\b@si', '<strong style="background-color:yellow">$1</strong>', $sString);  


压缩多个CSS文件
header('Content-type: text/css');  
ob_start("compress");  
function compress($buffer) {  
  /* remove comments */ 
  $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);  
  /* remove tabs, spaces, newlines, etc. */ 
  $buffer = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $buffer);  
  return $buffer;  
}  
 
/* your css files */ 
include('master.css');  
include('typography.css');  
include('grid.css');  
include('print.css');  
include('handheld.css');  
ob_end_flush();

代码片段就到这里,应用要灵活,重要的是参考开发思路,在实际的项目开发过程中还是要具体问题具体分析。
请尽量让自己的答案能够对别人有帮助

145个答案

默认排序 按投票排序
1 2 3 4 5 6 7 8