0
I want to use PHP and xamp/wamp to do the following task on my computer without the need to upload/download:
I have dozens of TXT files on the computer, each TXT containing only 1 name per line, no strokes, dots, etc.
I want to do a search, for example, for all people with surname "Silva" in these dozens of files, so PHP would read all TXT files, move all names with "Silva" to silva.txt and save the 2 files.
So far they have explained the following: The stop is to take the files and pass in php by a foreach on each line, add in the database, but before add do a search if there is already the data in the new file, then save the 2 files.
Can someone give me a light on how to do this?
I confess that I do not understand almost anything of PHP and I am beating head p/ do this foreach in several files at the same time, create this BD, create a new file, move everything, see if it has repeated, put in alphabetical order and save all the files later.
It’s complicated to work....
Post the code of what you have tried so far. And in what part of the code you have doubts, so it is easier to clarify the doubts.
– KevinF
If the files are in a single folder, it’s easier... Are??
– William Aparecido Brandino
They are all in the same folder. Find this here to read the files. Processing all files in a directory <? php $dh = dir ("/home/1www/"); while ($input = $dh->read()) { print $input . " <br>"; } $dh->close(); ?>
– Leandro Borges
To open the write file I found this: <?php $Fp = fopen("./data.txt", "w"); while (!feof($Fp)){ $char .= fgetc($Fp); } fclose($Fp); echo $char." <br><br>"; ?>
– Leandro Borges
<?php $file = file("list.txt"); foreach ($file as $i => $value) { } usort($files, "porData");
– Leandro Borges
I’m trying to put all these parts together and make it work.
– Leandro Borges
The files are simple: 001.txt, 005.txt, they have only one name per line, then ENTER, all TXT and in the same folder.
– Leandro Borges