파일의 단어 수를 계산해야하는 시나리오가 있습니다. 다른 파일 형식이 .doc
, .xls
, .pdf
및 .txt
입니다. 이 방법을 계산에 사용하고 있습니다 :doc, xls, pdf 및 txt 파일의 단어 수 계산 방법
<form method="post" action="" enctype="multipart/form-data">
<input type="file" name="docfile" />
<input type="submit" name="submit" />
</form>
<?php
if(isset($_POST['submit'])){
$file = $_FILES['docfile']['name'];
$file = str_replace(" ","_",$file);
//$file = file_get_contents($file);
$ext = pathinfo($file, PATHINFO_EXTENSION);
move_uploaded_file($_FILES['docfile']['tmp_name'],"uploads/".$file);
if($ext == "txt" || $ext == "pdf" || $ext == "doc" || $ext == "docx"){
$file = file_get_contents("uploads/".$file);
echo str_word_count($file);
}
}
?>
그러나 올바른 단어 수를 반환하지 않습니다.
무엇을 돌려 줍니까? 'str_word_count ($ file, 0)' – brbcoding
을 사용하면 카운트가 반환됩니다. – user2226181
나는 혼란 스럽다 ... 계산을 돌려 보내지 않는다? 하지만 그것은 계산을 반환하고 있습니까? – brbcoding