php查找文件内容关键字实例代码(2)
来源:未知 责任编辑:责任编辑 发表时间:2013-11-18 20:55 点击:次
$sResult = preg_match("/<title>.*</title>/i", $fileContent, $matchResult); $title = preg_replace(array("/(<title>)/i","/(</title>)/i"), "", $matchResult[0]); if (empty($title)) { return $default; } else { return $title; }}//获取文件描述信息function getFileDescribe($file,$length=200, $default="None describe"){ $metas = get_meta_tags($file); if ($meta[description] != "") { return $metas[description]; } $fileContent = getFileContent($file); preg_match("/(<body.*</body>)/is", $fileContent, $matchResult); $pattern = array("/(<[^x80-xff] >)/i","/(<input.*>) /i", "/(<a.*>) /i", "/(<img.*>) /i", "/([<script.*>]) .*([</script>]) /i","/&/i","/"/i","/'/i", "/s/"); $description = preg_replace($pattern, "", $matchResult[0]); $description = mb_substr($description, 0, $length)." ..."; return $description;}//加亮搜索结果中的关键字function highLightKeyword($text, $keyword, $color="#C60A00"){ $newword = "<font color=$color>$keyword</font>"; $text = str_replace($keyword, $newword, $text); return $text;}//获取文件大小(KB)function getFileSize($file){ $filesize = intval(filesize($file)/1024)."K"; return $filesize;}//获取文件最后修改的时间function getFileTime($file){ $filetime = date("Y-m-d", filemtime($file)); return $filetime;}//搜索目录下所有文件function searchFile($dir, $keyword){ $sFile = getFile($dir);