Skip to content

Instantly share code, notes, and snippets.

@JefterRocha
Created March 19, 2019 20:39
Show Gist options
  • Save JefterRocha/24489963606018f990b370a3e9e64aab to your computer and use it in GitHub Desktop.
Save JefterRocha/24489963606018f990b370a3e9e64aab to your computer and use it in GitHub Desktop.
<?php
// O bando em txt...
/*
#1|Jefter1|Rocha1|jefter1@email.com
#2|Jefter2|Rocha3|jefter2@email.com
#3|Jefter3|Rocha2|jefter3@email.com
*/
$path = 'database.txt';
$handle = fopen($path, 'r');
$datas = [];
if ($handle) {
while (($line = fgets($handle)) !== false) {
$row = $line;
$datas[] = explode('|', $line);
}
fclose($handle);
}
else {
echo 'Algum erro ocorreu!';
}
foreach($datas as $data) {
echo "id:$data[0]<br>nome: $data[1]<br>sobrenome:$data[2]<br>email:$data[3]<br><br>";
}
// Ou se preferir crie um array associativo.
$handledDatas = [];
foreach($datas as $data) {
$handledDatas[] = [
'id' => $data[0],
'nome' => $data[1],
'sobrenome' => $data[2],
'email' => $data[3]
];
}
print_r($handledDatas);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment