image


Valora:  3/5
Inicio » PHP » PHP Tutorial » Functions and libraries




Library

The use of libraries is extremely useful, it allows us to group several functions and variables in the same file so that we are able to include a library in different pages and make these functions easily available.

<!-- PHP Tutorial WebEstilo.com -->

<?php
   function CabeceraPagina()
   {
?>

   <FONT SIZE="+1">The header.</FONT><BR>
   <hr>
<?
   }
   
   function PiePagina()
   {
?>
   
   <hr>
   <FONT SIZE="-1">The footer</FONT><BR>
   Author: Joaquin Gracia
<?   
   }
?>


View code

Now we are going to create 2 pages that will use the previously defined library to get the two pages to have the same header and footer.

The statement used to include a library in our page is include("name of library")


<!-- PHP Tutorial WebEstilo.com -->
<html>
<head>
   <title>PHP Example</title>
</head>
<body>
<?php include("libreria01.phtml") ?>
<?php CabeceraPagina(); ?>

Page 1
<BR><BR><BR><BR><BR>

Content blalbl blalb alb<BR><BR>
that...<BR><BR>

end<BR><BR>

<?php PiePagina(); ?>
</body>
</html>

Execute View code
<!-- PHP Tutorial WebEstilo.com -->
<html>
<head>
   <title>PHP Example</title>
</head>
<body>
<?php include("libreria01.phtml") ?>
<?php CabeceraPagina(); ?>

Another page<BR><BR>

<?php PiePagina(); ?>
</body>
</html>

Execute View code






WebEstilo.com - Introduzca su e-mail y conozca las novedades. No hacemos Spam.
Google
  Web WebEstilo.com   
 
Valid HTML 4.01!
Última modificación:24 de Diciembre de 2004. Spain - España.
© 1998-2004 por Joaquin Gracia. Todos los derechos reservados.