Sie sind auf Seite 1von 4

Ejemplos PHP.

Mostrar cual de 2 números es el mayor (Uso del if)


<html>
<head>
<title>EjemploIf</title>
</head>
<body>
<?php
$a=5; $b=3;
if ( $a > $b )
echo “El mayor es A”. $a;
else
echo “El mayor es B”. $b;
?>
</body>
</html>

Mostrar los números del 1 al 10 (Uso del while)

<html>
<head>
<title>EjemploWhile</title>
</head>
<body>
<?php
$i = 1;
while ($i <= 10):
echo $i;
$i++;
endwhile;
?>
</body>
</html>

Mostrar toda la información de PHP (Función phpinfo() )

<html>
<head>
<title>FunciónPhpinfo</title>
</head>
<body>
<?php
echo phpinfo();
?>
</body>
</html>
Acceso restringido (Uso del if )

<html>
<head>
<title>Ejemplo</title>
</head>
<body>
<?php
$usuario = "Admin";
if($usuario == "Admin"){
echo "Bienvenido a la parte de
administración";
}elseif ($usuario == "Invitado"){
echo "Bienvenido a la página de Invitados";
}else{
echo "Bienvenido a la página de usuarios";
}
?>
</body>
</html>

Mostrar diferentes tamaños de letras que existen en html.

<Html>
<head>
<Title> Letras.php </Title>
</head>
<Body>
<?php
$size=1;
while ($size<=7) {
echo "<font size=$size> Tamaño $size </font> <br>";
$size++;
}
?>
</Body>
</Html>
Mostrar los múltiplos de 5, empezando en el 100 y acabando en el 500

<html>
<head>
<title>Múltiplos de 5</title>
</head>
<body>
<?php
$a=100
While ($a<=1000) {
echo “$a –”;
$a=$a+4;
}
?>
</body>
</html>
´
Ejemplos usando “case”
<html>
<head>
<title>EjemplosCase</title>
</head>
<body>
<?php
switch (expresión) {
case valor_1:
sentencia 1
break;
case valor_2:
sentencia 2
break;

case valor_n:
sentencia n
break;
default sentencia n+1
?>
</body>
</html>
<html>
<head>
<title>Case</title>
</head>
<body>
<?php
switch ($extension) {
case ("PDF"):
$tipo = "Documento Adobe PDF";
break;
case ("TXT"):
$tipo = "Documento de texto";
break;
case ("HTML"):
$tipo = "Documento HTML";
break;
default:
$tipo = "Archivo ": $extension;
}
print ($tipo);
?>
</body>
</html>

Das könnte Ihnen auch gefallen