lunes, 27 de abril de 2009

LENGUAJE DE PROGRAMACION PHP EJEMPLOS UNIDAD 1

UNIVERSIDAD NACIONAL EXPERIMENTAL SIMON RODRIGUEZ
NUCLEO LOS TEQUES
ASIGNATURA: LENGUAJE 2.
FACILITADOR: MIGUEL ANGEL GAVIDIA
ABRIL 2009 Telf. 0412-721.11.48 usrmiguelgavidia@yahoo.com


EJEMPLOS BASICOS CORRESPONDIENTES A LA UNIDAD 1

E01

#/ ejemplo primero hola mundo /#
echo " primer programa en php muy facil hola mundo "; //primer ejemplo
echo "

fin del primer ejemplo
"; // muestra mensaje
echo "
ver otro ejemplo "; // fin del ejemplo
echo "
"; //
?>


E02

< html>
< head>< title> ejemplo e02 muy sencillo < /title>< /head>
< body>
#/ ejemplo segundo /#
echo "

saludos a todos "

; //segundo ejemplo
echo "

fin del primer ejemplo
"; // muestra mensaje
echo "
ver otro ejemplo "; // fin del ejemplo
echo "
"; //
?>
< /body>
< /html>

E03.html

< html>
< head>
< title>su nombre es < /title>
< /head>
< body>
< form method="post" action="e03a.php">
cual es su nombre ?
< input name="nombre">
< br />
< input type="submit" name="enviar" value="enviar">
< /form>
< /body>
< /html>

E03a.php

< html>
< body>
tu nombre completo desde php es
echo "

el nombre fue dado

";
?>
< /body>
< /html>


E04.php

< html>
< head>< title> ejemplo e04 muy sencillo < /title>< /head>
< body>
#/ ejemplo cuarto /#
/* este es un script utilizado para mostrar la funcion print */
print ("

uso de la funcion print

\n") ; //cuarto ejemplo
echo "

fin del cuarto ejemplo
"; // muestra mensaje
echo "
ver otro ejemplo "; // fin del ejemplo
// ahora saldremos del modo php
echo "
"; //
?>
<>
// tambien se pueden utilizar las etiquetas php abreviadas
echo "este ejemplo 2009 miguel gavidia abc ;
php xxxx se le da el nombre inicial de
miguel salas \n";
?>
< /body>
< /html>


E05.php

#/ ejemplo cinco pagina 26 libro ibm. /#
echo " programa en php muy facil hola mundo e05print26 "; //quinto ejemplo
print("< html>\n");
print("< head>\n");
print("< title> ejemplo php script < /title>\n");
print("< /head>\n");
print("< body>\n");
print("< h1> holo mundo php < h1>\n");
print("en 1995 < b> rasmus lerdorf < /b> creó < b>PHP< /b)
dondole el nombre inicial de personal home page tools luego ese
nombre fue cambiado a PHP Hipertext Preprocessor \n
.\n");
print("< /body>\n");
print("< /html>\n");
?>


E06.php
< html>
< head>
< title> ejemplo 2.1 php script etiquetas php pag. 35 e06enbebido < /title>
< /head>
< body>
#/ ejemplo seis /#
echo " esta es la forma recomendada para delimitar codigo php
\n ";
?>

aqui estamos en modo html


echo " esta es la forma abreviada de las etiquetas php
\n ";
?>
< script language="php">
echo " en este segmento utilizaremos la etiqueta script
\n ";
< /script>
< %= "opcionalmente puedo utilizar las etiquetas asp pero esta opcion debe estar configurada en el php.ini
\n " %>
< /body>
< /html>


E07.php

< html>
< head>
< title> sintaxix basica de php segun pag 38 < /title>
< /head>
< body>

sintaxix super basica2 de phph7 "?>
"?>
echo " esta instruccion finaliza con punto y coma pues le sigue otra instruccion
\n ";
echo " una funcion no es sensible a mauscula ni minuscula php
\n ";
// no es becesario finalizar con punto y coma
?>
< hr />< ! estoy en modo html ->
/*
comienzo del segundo segmento de codogo.
se pueden escribir varias lineas de comentarios */
print (" mostraremos un numero
\n ");
$nume=250;
echo "el numero es ",$nume;
// ?>
< hr />
< script language="php">
echo "en este segmento utilizaremos la etiqueta script
\n ";
< /script>
< hr />
este es el fin\n"?>
< /body>
< /html>


Equipo.html

< html>
< head>
< title>equipo favorito< /title>
< /head>
< body>
< form method="post" action="verequipo.php">
ACTION ES LA APLICACION QUE SE VA A PROCESAR QUE ENVIA EL USUARIO
MEDIANTE EL FORMULARIO
method indica si el usiario del formulario va a enviar datos (post)
o recibir recogerlos (get). por regla siempre se envia con post
en la etiqueta form vienen los campos de entrada
cual es tu equipo de futbol favorito ?
nuestra el campo de texto
< input name="equipo">
< br />
< input type="submit" name="enviar" value="enviar">
< /form>
< /body>
< /html>

Verequipo.php
< html>
< body>
tu equipo favorito es
echo "

$equipo

";
?>
< /body>
< /html>

A01
< body>
$myvar = "Hola. Este es mi primer script en PHP \n";
//Esto es un comentario
echo $myvar;
?>
< /body>

A07.php
< body>
$ciudad = array("París", "Roma", "Sevilla", "Londres");
$numelentos = count($ciudad);
for ($i=0; $i < $numelentos; $i++)
{
print ("La ciudad $i es $ciudad[$i]
\n");
}
?>
< /body>

A08.php

< body>
function suma ($x, $y) {
$x = $x + 1;
return $x+$y;
}
$a = 1; $b = 2;
//parámetros por valor
echo suma ($a, $b); // imprimirá 4
echo $a; // imprimirá 1
//parámetros por referencia
echo suma ($a, $b); // imprimirá 4
echo $a; //imprimirá 2
?>
< /body>

A10.php

< body>
function contador () {
static $count = 0;
$count = $count + 1;
return $count;
}
echo contador()."
"; // imprimirá 1
echo contador()."
"; // imprimirá 2
?>
< /body>


A11.php

< body>
$a = 1;
function ver_a(){
global $a;
echo $a."
";
// imprimirá el valor de $a
$a += 1;
}
echo ver_a(); // imprimirá 1
echo ver_a(); // imprimirá 2
$a = 7;
echo ver_a(); // imprimirá 7
echo ver_a(); // imprimirá 8

?>
< /body>


Varformularios.html


< html>
< head>< title>Formularios PHP< /title>< /head>
< body>
< form name="miformulario" action="VarFormularios.php">
< table border="1">

< td>Código:
< td>
< td>Nombre:
< td>
< /tr>
< tr>
< td>Sueldo:
< td>
< /tr>
< tr>
< td>
< td>
< /tr>
< /table>
< /form>
< /body>
< /html>

Varformularios.php


< html>
< head>< title>Formularios PHP< /title>< /head>
< body>
< center>
< h2>Datos introducidos en formulario< /h2>
< table border="1">
< tr>
Código:< /td>

// $CodEmpleado="aaaa";
echo $CodEmpleado;
?>
Nombre:< /td>

// $Nombre="aaabbbbb";
echo $Nombre;
?>
< /td>
< /tr>
< tr>
< td>Sueldo:< /td>
< td>
// $Sueldo=200;
echo $Sueldo;
?>
< /td>< /tr>
< /table>
< /center>
< hr />
< /body>
< /html>

No hay comentarios:

Publicar un comentario