-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuncoes.php
More file actions
62 lines (59 loc) · 1.59 KB
/
funcoes.php
File metadata and controls
62 lines (59 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/*Aula 1 : Aprender sobre condicionamentos*/
function validarBolo($ingredientesPost){
if (array_key_exists('ingredientes', $ingredientesPost)) {
$ingredientes = explode("\n", $ingredientesPost['ingredientes']);
$ingredientes = array_map('trim',$ingredientes);
$ovo = $farinha = $leite = $manteiga = $fermento = false;
foreach ($ingredientes as $key => $ingrediente) {
switch ($ingrediente) {
case 'ovo':
$ovo = true;
break;
case 'farinha':
$farinha = true;
break;
case 'leite':
$leite = true;
break;
case 'manteiga':
$manteiga = true;
break;
case 'fermento':
$fermento = true;
break;
}
}
if ($ovo && $farinha && $leite && $manteiga && $fermento) {
$resultado = 'Bolo Aceito.';
} else {
$resultado = 'Ingredientes incorreto.';
}
return $resultado;
}
}
/*Aula 2 - Aprendendo sobre lacos repetitivos*/
function LeituraArquivoCSV($arquivoCSV){
if (pathinfo($arquivoCSV, PATHINFO_EXTENSION) == "csv") {
$arquivo = file_get_contents($arquivoCSV);
$linhas = explode("\n", $arquivo);
$tabela = '';
foreach ($linhas as $key => $linha) {
if ($key == 0) {
$colunas = explode(";", $linha);
foreach ($colunas as $coluna) {
$tabela = $tabela . "<td><strong> $coluna </strong></td>";
}
} else {
$colunas = explode(";", $linha);
foreach ($colunas as $coluna) {
$tabela = $tabela . "<td> $coluna </td>";
}
}
$tabela = $tabela . "</tr> <tr>";
}
return "<table border = '1'> <tr> $tabela </tr> </table>";
} else {
return "Arquivo Invalido";
}
}