我只需要读取目录中的 pdf 文件,然后读取每个文件的文件名,然后我将使用文件名重命名一些 txt 文件。我试过只使用eregi 功能。但它似乎无法阅读我需要的所有内容。如何读好它们?这是我的代码:
$savePath ='D:/dir/';
$dir = opendir($savePath);
$filename = array();
while ($filename = readdir($dir)) {
if (eregi("\.pdf",$filename)){
$read = strtok ($filename,"."); //get the filenames
//to rename some txt files using the filenames that I get before
//$testfile is text files that I've read before
$testfile = "$read.txt";
$file = fopen($testfile,"r") or die ('cannot open file');
if (filesize($testfile)==0){}
else{
$text = fread($file,55024);
fclose($file);
echo "</br>"; echo "</br>";
}
}