0

i want write a code in php that go to txt file in dir "file" and look to line 2 and take category and subject from line 3 for a menu in my site.

   function arrayDuplicate($array) 
{ 
return array_unique(array_diff_assoc($array1,array_unique($array1))); 
}

$number =Countdir('file');

for ($i = 1; $i <= $number; $i++) {

$myFile = file; 
$myFile .= '/'; 
$myFile .= $i;
$myFile .= ".txt";

$cat = ReadLine($myFile, 2);
$arr1 .= "'"; 
$arr1 .= $cat; 
$arr1 .= "'"; 
$arr1 .= ","; 
$arr1 .= " "; 
print($arr1);
}
$arr = array($arr1);

$result = arrayDuplicate($arr);

in 1.txt "1 cat1 subject1 file1.pdf 1369947340"

in 2.txt "2 cat1 subject2 file2.pdf 1369947310"

in 3.txt "3 cat2 subject3 file3pdf 1369947304"

i want menu cat1 | cat2.. and when you touch cat1 you see subject1 and subject2 ,cat2 see subject3..

My code show me cat1 | cat1 | cat2

Em Fhal
  • 152
  • 12

1 Answers1

0

This is a very difficult way to do something very easy.

Might I suggest you use a MYSQL database as the source for your menu?

If you insist on doing it the hard way:

Since you know the names of the files, simply create an array containing their names vis:

$files=array("/directoryname/1.txt",...etc);

wrap your code in a foreach loop on $files.

Robert Seddon-Smith
  • 987
  • 1
  • 9
  • 13