PHP/Utility Function/require

Материал из Web эксперт
Перейти к: навигация, поиск

require() operates like include(), including a template.

   <source lang="html4strict">

It has this syntax: require(file insertion_file) The insertion_file will be included in the script. // A sample file to be inserted (init.tpl) <? $site_title = "PHP"; $contact_email = "w@hotmail.ru"; $contact_name = "Sales"; ?> //Making use of init.tpl <? require ("init.tpl"); ?>

 </source>
   
  


Using require to Load Files in PHP

   <source lang="html4strict">

//File: library.inc <?

   function is_leapyear($year = 2004) {
       $is_leap = (!($year % 4) && (($year % 100) || !($year % 400)));
       return $is_leap;
   }

?>

<?php

   require ("library.inc");     // Parentheses are optional
   $leap = is_leapyear(2003);

?>

 </source>