|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Indexing text files in a folder
I'm newbie on Php. I cannot write codes but only modify.
I need a code doing this: I'll put text files in a folder like file1.txt,file2.txt ... I want to search this files, list most recent 10 and if files call, script will put into the site design with <pre> tags. I hope I can explain what I need. I dont know Php is suitable for that. Please help me about this. Thanks. |
|
#2
|
|||
|
|||
|
RE: Indexing text files in a folder
Php can do what you want. Right now I haven't the time to code the function but I'm sure some other happy soul here at codewalkers.com will... |
|
#3
|
|||
|
|||
|
RE: Indexing text files in a folder
not sure what you mean when you say "if files call" but as for the rest..
you'll read a dir, store the contents of the dir into an array. using your naming convention (file1, file2 etc..) you'll probably want to run a natsort function on your array. then run a recursive function on your array to search the last 10 (most recent) files stored from the dir.. or just compare last-modified times to determin the most recent that way.. hope that makes sense. um.. i could come up with an example if you need one. the php.net manual should help you get started though |
|
#4
|
|||
|
|||
|
RE: Indexing text files in a folder
you can use something like this I think. Fix it according to your needs.
to call the function add this line to your php page directory(your/files/parh); function directory($result) { $handle=opendir("$result"); GLOBAL $icerik; $count = 0; # Gather the files, and put them in a array while( $file = readdir( $handle) ) { $file_array[] = $file; } foreach( $file_array as $file ) { if( $file == ".." || $file == "." ) { continue; } if( !eregi( ".txt$", $file ) ) { continue; } $file=eregi_replace(".txt$",".txt",$file); # Display the file with a link echo"<A href="index.php?variables_to_call_file">$file</A> || "; # Count the file that was displayed $count++; } echo""; #close thedirectory you used closedir($handle); # Display Number of files that were displayed echo"<P> There are <b>$count</b> tests in this section"; return $result; } |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Indexing text files in a folder |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|