8
I have a text file with many emails and I want to save everything in a database, as I do to get each email from the file in PHP?
The emails are separated by comma.
8
I have a text file with many emails and I want to save everything in a database, as I do to get each email from the file in PHP?
The emails are separated by comma.
7
You can use the function file()
to read the e-mails and put them in a array
.
$texto = file('emails.txt');
Now just use the explode()
to capture the emails and separate them by the comma.
$emails = explode(",", $texto);
Only additional reading: http://php.net/manual/en/function.fgetcsv.php
2
Starting from the pre-presumed that the bank has the emails table, and that the file is teste.txt
:
// Pega o conteudo do arquivo teste.txt
$arquivo_texto = file_get_contents('teste.txt');
// Cria um array com os emails do arquivo teste.txt
$emails = explode(',', $arquivo_texto);
// Abre uma conexão com o banco de dados mysql
$con = new PDO("mysql:host=localhost;dbname=nome_do_banco", "root", "");
// Loop para inserção no banco de dados
foreach ($emails as $value) {
$rs = $con->query("INSERT INTO emails VALUES ?");
$rs->bindParam(1, $value);
$rs->execute();
}
Browser other questions tagged php email
You are not signed in. Login or sign up in order to post.
Exist only emails in this list?
– Erlon Charles
Yeah, it’s just emails
– Carol