PHPͳ¼ÆĿ¼ÏµÄÎļþ×ÜÊý¼°´úÂëÐÐÊý£¨È¥³ý×¢Êͼ°¿ÕÐУ©
ÔÚ¿ª·¢µÄʱºò£¬ÎªÁËͳ¼Æ¿ª·¢³öµÄ´úÂë×ÜÐÐÊý¼°Îļþ×ÜÊý£¬ÔÚûÓÐʹÓù¤¾ßµÄʱºò£¬×ÜÊÇҪȥһ¸öÎļþÒ»¸öÎļþµÄ²éÕÒ£¬Îļþ¼Ð²ã´ÎÉÙ»¹ÐУ¬²ã´Î¶àµÄʱºò¾ÍÀÛËÀÈË
ÁË£¬ËäȻ֪µÀÄ¿Ç°¿ÉÄÜÒ²ÊÇ´æÔÚÕâÖÖͳ¼Æ¹¤¾ß¿ÉÒÔʹÓ㬵«Êǵ±Ê±¾ÍÏñÈç¹û×Ô¼ºÄÜдһ¸öͳ¼Æ·½·¨£¬Ã¿´ÎҪͳ¼ÆÖ»ÒªÖ´ÐÐÒ»´Î¾ÍÐУ¬¾ÍÄܵõ½×Ô¼ºÏëÒªµÄ½á¹û£¬ÕâÑù
¼È²»Óð²×°Í³¼Æ¹¤¾ßµÄÈí¼þ£¬¶øÇÒҲûÓÐÁËͳ¼Æ¹¦Äܹ¤¾ßµÄѧϰ³É±¾£¬Ò²ÄÜѧÒÔÖÂÓþͺÃÁË£¬ÓÚÊǾÍдÁ˶δúÂ룬ÕâÑùÓÃÆðÀ´Ò²ºÜ·½±ã£¬Ö»ÊÇÔËÐÐϳÌÐò¡£
Õâ¸öÀàµÄÔʼÔÐÍÊÇÒ»¶Ñfunction£¬£¨·¢±íÔÚÍⲩµØÖ·ÖеÄjavaeyeÖУ©£¬ÊÇÔÚÒ»¸öÅúÃüÁî²»ÄÜÂú×ãµÄÇé¿öϵIJúÎï¡£ÒòΪûÓÐÉîÈëÑо¿¹ýÅúÃüÁ
ËùÒÔÅúÃüÁîÖ»ÄÜͳ¼Æ×ÜÎļþÊý£¬¼°Ã¿¸öÎļþµÄÈ¥³ý¿ÕÐÐÖ®ºóµÄ×ÜÐÐÊý£¬¼°ËùÓÐÎļþÈ¥³ý¿ÕÐÐÖ®ºóµÄ×ÜÐÐÊý£¬È´Ã»ÓÐÈ¥³ý×¢ÊÍÐеŦÄÜ¡£ºóÀ´ÊºóÕûÀíÁËÏÂÕâ¶Ñº¯Êý£¬
±à³ÉÒ»¸öÀàÀ´Ê¹Ó㬾ͷ½±ã¶àÁË¡«¡«Ò²ºÃ¹ÜÀí¡£
µ«ÊÇÎÒÉîÖªÕâ¸öÀ໹ÓкܶàµÄȱÏÝ£¬ÔÚÆ¥ÅäµÄ¹æÔòÉÏҲûÓкÜÍêÃÀµÄдÉϹæÔò¡£ËùÒÔ·ÅÕâÀ﹩´ó¼Ò²éÔļ°Åú©¡«ËùÒÔÈç¹ûÓÐÏë·¨¿ÉÒÔÍêÉÆÕâ¸ö¹¦ÄܵĻ¶Ó¸øÎÒÁôÑÔ¡«¡«
<?php /** * @author xiaoxiao <x_824@sina.com> 2011-1-12 * @link http://xiaoyaoxia.cnblogs.com/ * @license * ͳ¼ÆĿ¼ÏµÄÎļþÐÐÊý¼°×ÜÎļþÊý¡¤¡¤È¥³ý×¢ÊÍ */ $obj = new CaculateFiles(); //Èç¹ûÉèÖÃΪfalse,Õâ²»»áÏÔʾÿ¸öÎļþµÄÐÅÏ¢£¬·ñÔòÏÔʾ $obj->setShowFlag(false); //»áÌø¹ýËùÓÐAll¿ªÍ·µÄÎļþ $obj->setFileSkip(array('All')); $obj->run("D:\PHPAPP\php\_tests"); //ËùÓÐÎļþ£¬£¨Ä¬ÈϸñʽΪ.php) $obj->setFileSkip(array()); $obj->run("D:\PHPAPP\php"); $obj->setShowFlag(true); //Ìø¹ýËùÓÐIºÍA¿ªÍ·µÄÎļþ£¬£¨±ÈÈç½Ó¿ÚºÍ³éÏóÀ࿪ͷ£© $obj->setFileSkip(array('I', 'A')); $obj->run("D:\PHPAPP\php"); /** * Ö´ÐÐĿ¼ÖÐÎļþµÄͳ¼Æ£¨°üÀ¨ÎļþÊý¼°×ÜÐÐÊý * * 1¡¢Ìø¹ýÎļþµÄʱºò£º * Æ¥ÅäµÄ¹æÔòÖ»ÊÇ´ÓÎļþÃûÉÏ×ÅÊÖ£¬Æ¥ÅäµÄ¹æÔòÒ²½öÏÞÔÚ¿ªÍ·¡£ * 2¡¢Ìø¹ýÎļþÖеÄ×¢ÊÍÐУº * Æ¥ÅäµÄ¹æÔòÖ»ÊÇ´Ó×¢ÊͶÎÂäµÄÍ·²¿Æ¥Å䣬Èç¹û³öÏÖ// ¼° *¼° #¼°/*¿ªÍ·µÄÐм°¿ÕÐлᱻÌø¹ý¡£ËùÒÔÀàËÆ/*ÕâÖֶູעÊÍ£¬Ã¿ÐеĿªÍ·¶¼±ØÐë¼ÓÉÏ*ºÅ£¬·ñÔòÎÞ·¨Æ¥Åäµ½ÕâÖÖµÄ×¢ÊÍ¡£ * 3¡¢Ä¿Â¼¹ýÂË£º * Æ¥ÅäµÄ¹æÔòÊÇ´ÓĿ¼ÃûµÄÈ«ÃûÆ¥Åä */ class CaculateFiles { /** * ͳ¼ÆµÄºó׺ */ private $ext = ".php"; /** * ÊÇ·ñÏÔʾÿ¸öÎļþµÄͳ¼ÆÊý */ private $showEveryFile = true; /** * ÎļþµÄµÄÌø¹ý¹æÔò */ private $fileSkip = array(); /** * ͳ¼ÆµÄÌø¹ýÐйæÔò */ private $lineSkip = array("*", "/*", "//", "#"); /** * ͳ¼ÆÌø¹ýµÄĿ¼¹æÔò */ private $dirSkip = array(".", "..", '.svn'); public function __construct($ext = '', $dir = '', $showEveryFile = true, $dirSkip = array(), $lineSkip = array(), $fileSkip = array()) { $this->setExt($ext); $this->setDirSkip($dirSkip); $this->setFileSkip($fileSkip); $this->setLineSkip($lineSkip); $this->setShowFlag($showEveryFile); $this->run($dir); } public function setExt($ext) { trim($ext) && $this->ext = strtolower(trim($ext)); } public function setShowFlag($flag = true) { $this->showEveryFile = $flag; } public function setDirSkip($dirSkip) { $dirSkip && is_array($dirSkip) && $this->dirSkip = $dirSkip; } public function setFileSkip($fileSkip) { $this->fileSkip = $fileSkip; } public function setLineSkip($lineSkip) { $lineSkip && is_array($lineSkip) && $this->lineSkip = array_merge($this->lineSkip, $lineSkip); } /** * Ö´ÐÐͳ¼Æ * @param string $dir ͳ¼ÆµÄĿ¼ */ public function run($dir = '') { if ($dir == '') return; if (!is_dir($dir)) exit('Path error!'); $this->dump($dir, $this->readDir($dir)); } /** * ÏÔʾͳ¼Æ½á¹û * @param string $dir Ŀ¼ * @param array $result ͳ¼Æ½á¹û£¨°üº¬×ÜÐÐÊý£¬ÓÐЧº¯Êý£¬×ÜÎļþÊý */ private function dump($dir, $result) { $totalLine = $result['totalLine']; $lineNum = $result['lineNum']; $fileNum = $result['fileNum']; echo "*************************************************************\r\n<br/>"; echo $dir . ":\r\n<br/>"; echo "TotalLine: " . $totalLine . "\r\n<br/>"; echo "TotalLine with no comment and empty: " . $lineNum . "\r\n<br/>"; echo 'TotalFiles:' . $fileNum . "\r\n<br/>"; } /** * ¶ÁȡĿ¼ * @param string $dir Ŀ¼ */ private function readDir($dir) { $num = array('totalLine' => 0, 'lineNum' => 0, 'fileNum' => 0); if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if ($this->skipDir($file)) continue; if (is_dir($dir . '/' . $file)) { $result = $this->readDir($dir . '/' . $file); $num['totalLine'] += $result['totalLine']; $num['lineNum'] += $result['lineNum']; $num['fileNum'] += $result['fileNum']; } else { if ($this->skipFile($file)) continue; list($num1, $num2) = $this->readfiles($dir . '/' . $file); $num['totalLine'] += $num1; $num['lineNum'] += $num2; $num['fileNum']++; } } closedir($dh); } else { echo 'open dir <' . $dir . '> error!' . "\r"; } return $num; } /** * ¶ÁÈ¡Îļþ * @param string $file Îļþ */ private function readfiles($file) { $str = file($file); $linenum = 0; foreach ($str as $value) { if ($this->skipLine(trim($value))) continue; $linenum++; } $totalnum = count(file($file)); if (!$this->showEveryFile) return array($totalnum, $linenum); echo $file . "\r\n"; echo 'TotalLine in the file:' . $totalnum . "\r\n"; echo 'TotalLine with no comment and empty in the file:' . $linenum . "\r\n"; return array($totalnum, $linenum); } /** * Ö´ÐÐÌø¹ýµÄĿ¼¹æÔò * @param string $dir Ŀ¼Ãû */ private function skipDir($dir) { if (in_array($dir, $this->dirSkip)) return true; return false; } /** * Ö´ÐÐÌø¹ýµÄÎļþ¹æÔò * @param string $file ÎļþÃû */ private function skipFile($file) { if (strtolower(strrchr($file, '.')) != $this->ext) return true; if (!$this->fileSkip) return false; foreach ($this->fileSkip as $skip) { if (strpos($file, $skip) === 0) return true; } return false; } /** * Ö´ÐÐÎļþÖÐÐеÄÌø¹ý¹æÔò * @param string $string ÐÐÄÚÈÝ */ private function skipLine($string) { if ($string == '') return true; foreach ($this->lineSkip as $tag) { if (strpos($string, $tag) === 0) return true; } return false; } }
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ