# 1.- Primeros pasos
<html>
<body> <?php echo "¡Hola, soy un script de PHP!"; ?> </body>
</html>
# Ejecicio 1
Escribir un número y indicarle que hora es, dia, noche, madrugada.
<?php
$horario = $_GET['hora'];
if($horario >= 6 && $horario <= 12){
echo "<p>Todavia es mañana!</p>";
}else if($horario >= 13 && $horario <= 20){
echo "<p>Estamos de tarde!</p>";
}else{
echo "<p>Estamos de madrugada!</p>";
}
?>
Estamos: <?php echo $horario ?>
<br><br><a href="horario.html"><button>Atras</button></a>
<!DOCTYPE html>
<html>
<head>
<title>Horario</title>
<meta charset="UTF-8">
</head>
<body>
<form action="horario.php" method="get">
Que hora es?: <input type="number" name="hora" min="0" max="24" ><br>
<input type="submit" value="enviar">
</form>
</body>
</html>
# Ejecicio 2
test.php
<!DOCTYPE html>
<html>
<head>
<title>Conversor de Unidades</title>
</head>
<body>
<form id="menu" name="menu" method="POST" action="testrespuesta.php">
<li name="respuestaUno">
<?php
$pregunta1 = ["JS", "PHP", "CSS"];
echo "<h2>Cuales no es un lenguajes de programación</h2>" ;
for ($x=0;$x<count($pregunta1); $x++)
echo "<input type='radio' name='lenguajes' value='".$pregunta1[$x]."'>" .$pregunta1[$x] . "<br> ";
echo "<h2>Cual de las siguientes opciones es la correcta para agregar un comentario en PHP</h2> ";
$pregunta2 = ["&......&", "//....", "a y b"];
for ($x=0;$x<count($pregunta2); $x++)
echo "<input type='radio' name='ambos' value='".$pregunta2[$x]."'>" .$pregunta2[$x] . "<br> ";
?>
<input type="submit" value="Enviar" />
</form>
</body>
</html>
testrespuesta.php
<?php
$uno = 0;
$dos = 0;
$respuesta_lenguaje = $_POST['lenguajes'];
$respuesta_ambos = $_POST['ambos'];
$res= ["CSS","a y b"];
echo var_dump($_POST);
echo "dato " .$res[0];
echo "otro ".$respuesta_lenguaje;
$resul;
if(strcmp($res[0], $respuesta_lenguaje) == 0){
$uno = 1;
echo "<p>acertaste la respues 1</p>";
}else{
echo "<p>fallaste en la respues 1</p>";
}
if($res[1] ==$respuesta_ambos){
$dos = 1;
echo "<p>acertaste la respues 2</p>";
}else{
echo "<p>fallaste en la respues 2</p>";
}
$resul = $uno + $dos;
echo $resul;
?>
# Clases Polimorfismo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
include_once 'Gato.php';
$gato = new Gato("hembra ", "romana ");
echo $gato;
var_dump($gato) ; // Muestra todos los datos
?>
</body>
</html>
//Archivo Gato.php
<?php
include_once 'Mamifero.php';
class Gato extends Mamifero{
private $raza;
public function __construct(string $sexo ,string $raza ){
parent::__construct($sexo);
if(isset($raza)){
$this->raza = $raza ;
echo parent:: getSexo();
}else{
echo $this->raza = "siames";
}
}
public function __toString(){
return $this->raza;
}
}
?>
//Mamifero.php
<?php
include_once 'Animal.php';
abstract class Mamifero extends Animal{
public function __construct($sexo)
{
parent:: __construct($sexo);
}
}
?>
//Animal.php
<?php
class Animal{
private $sexo;
public function __construct(string $s){
if(isset($s)){
$this->sexo = $s;
}else{
$this->sexo = "macho";
}
}
public function __toString(){
return $this->sexo;
}
public function getSexo(){
return $this->sexo;
}
}
?>