예제 #1
0
    // para mostrar el mensaje.
    if ($nombre == null) {
        $textoAdv = "No has introducido el nombre.";
        $advertencia = true;
    } elseif (isExiste($fileText, $nombre) && $tel == null) {
        baja($fileText, $nombre);
        $textoCorrect = "{$nombre} se ha dado de baja.";
        $correct = true;
    } elseif (isExiste($fileText, $nombre) && $tel != null) {
        modificar($fileText, $nombre, $tel);
        $textoCorrect = "{$nombre} con teléfono {$tel} se ha modificado.";
        $correct = true;
    } elseif (!isExiste($fileText, $nombre) && $tel == null) {
        $textoAdv = "No has introducido el teléfono.";
        $advertencia = true;
    } elseif (!isExiste($fileText, $nombre) && $tel != null) {
        alta($fileText, $nombre, $tel);
        $textoCorrect = "{$nombre} con teléfono {$tel} se ha dado de alta.";
        $correct = true;
    }
}
// En caso de existir el archivo muestra los datos en una tabla.
if (filesize($fileText)) {
    echo "<table><tr><th>Nombre</th><th>Número</th></tr>";
    $fichero = fopen($fileText, "r") or die("ERROR al leer el fichero.");
    $lineas_fichero = file($fileText);
    for ($i = 0; $i < count($lineas_fichero); $i++) {
        $celda = explode(":", $lineas_fichero[$i]);
        echo "<tr><td>{$celda['0']}</td><td>{$celda['1']}</td></tr>";
    }
    echo "</table><br/>";
예제 #2
0
 // para mostrar el mensaje.
 if ($nombre == null) {
     $textoAdv = "No has introducido el nombre.";
     $advertencia = true;
 } elseif (isExiste($agenda, $nombre) && $tel == null) {
     baja($agenda, $nombre);
     $textoCorrect = "{$nombre} se ha dado de baja.";
     $correct = true;
 } elseif (isExiste($agenda, $nombre) && $tel != null) {
     modificar($agenda, $nombre, $tel);
     $textoCorrect = "{$nombre} con teléfono {$tel} se ha modificado.";
     $correct = true;
 } elseif (!isExiste($agenda, $nombre) && $tel == null) {
     $textoAdv = "No has introducido el teléfono.";
     $advertencia = true;
 } elseif (!isExiste($agenda, $nombre) && $tel != null) {
     alta($agenda, $nombre, $tel);
     $textoCorrect = "{$nombre} con teléfono {$tel} se ha dado de alta.";
     $correct = true;
 }
 // Si el tamaño de la agenda es mayor de cero por tanto no esta vacia muestra lo que contiene el array agenda.
 if (count($agenda) != 0) {
     // Pinta una tabla y sus cabeceras.
     echo "<table><tr><th>Nombre</th><th>Teléfono</th></tr>";
     // Va mostrando los indices que son los nombres y los valores que son los numeros de telefono.
     foreach ($agenda as $indice => $valor) {
         echo "<tr><td>{$indice}</td><td>{$valor}</td></tr>";
     }
     echo "</table>";
 } else {
     // En caso de que la agenda este vacia muestra el siguiente mensaje.