0
나는 5000 파일에 대해 온라인으로 단어 파일을 가지고 있는데, 어떤 키워드에 대해서도 모든 파일에서 검색해야합니다. 예를 들어, "Human Resource"는 입니다. 거대한 단어 파일을 검색하는 가장 좋은 방법
그래서 나는 워드 파일을 읽을 기능을 만들었지 만 내 문제 내가예제 코드 서버의 메모리를 죽일 작업을 처리 같아요
<?php
function doc_to_text($input_file){ //for doc files
$file_handle = @fopen($input_file, "r"); //open the file
$stream_text = @fread($file_handle, filesize($input_file));
$stream_line = explode(chr(0x0D),$stream_text);
$output_text = "";
foreach($stream_line as $single_line){
$line_pos = strpos($single_line, chr(0x00));
if(($line_pos !== FALSE) || (strlen($single_line)==0)){
$output_text .= "";
}else{
$output_text .= $single_line." ";
}
}
$output_text = preg_replace("/[^a-zA-Z0-9\s\,\.\-\n\r\[email protected]\/\_\(\)]/", "", $output_text);
return $output_text;
}
function docx_to_text($input_file){ //for docx files
$xml_filename = "word/document.xml"; //content file name
$zip_handle = new ZipArchive;
$output_text = "";
if(true === $zip_handle->open($input_file)){
if(($xml_index = $zip_handle->locateName($xml_filename)) !== false){
$xml_datas = $zip_handle->getFromIndex($xml_index);
$xml_handle = DOMDocument::loadXML($xml_datas, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING);
$output_text = strip_tags($xml_handle->saveXML());
}else{
$output_text .="";
}
$zip_handle->close();
}else{
$output_text .="";
}
return $output_text;
}
?>
은 그럼 루프를 만들고 stristr하여 키워드를 모든 파일을 검사합니다() 함수를 호출하고 stristr()이 true를 반환하면 스크립트는 파일 이름을 인쇄합니다.
다른 해결책이 있습니까?
참조 : stristr()
네, 검색 색인을 조기에 만들어서 검색 할 수 있습니다. – zerkms
awk, sed를 사용해 보셨습니까? – ziollek