从读取txt打开目录

时间:2014-01-08 14:20:43

标签: php search directory dir

从.txt打开和搜索数据的PHP脚本是:

function explodeRows($data) {
  $rowsArr = explode("\n", $data);
  return $rowsArr;
}

function explodeTabs($singleLine) {
  $tabsArr = explode("\t", $singleLine);
  return $tabsArr;
}
$filename = "/txt/name.txt";
$handle   = fopen($filename, 'r');
$data     = fread($handle, filesize($filename));
$rowsArr  = explodeRows($data);
for($i=0;$i<count($rowsArr);$i++) {
  $lineDetails = explode("|",$rowsArr[$i]);
  if ($kodas == $lineDetails[2]) {
    $link3=$lineDetails[4];
    echo "";
     } }
fclose($handle);

它运行良好,但现在我将name.txt传输到另一个文件夹(文件夹名称txt)。如何制作,首先打开此文件夹并搜索打开的name.txt

1 个答案:

答案 0 :(得分:0)

$filename = "txt/name.txt";
$handle   = fopen($filename, 'r');
$data     = fread($handle, filesize($filename));
$rowsArr  = explodeRows($data);