Include a php file in PHP

Description

The following code shows how to include a php file.

Example


/*from w  w w  .  ja va  2 s  . c o  m*/
//data.php
/*
<?php
  $monthName = array(
    1=>"January", "February", "March",
    "April", "May", "June",
    "July", "August", "September",
    "October", "November", "December",

    "Jan"=>"January", "Feb"=>"February",
    "Mar"=>"March", "Apr"=>"April",
    "May"=>"May", "Jun"=>"June",
    "Jul"=>"July", "Aug"=>"August",
    "Sep"=>"September", "Oct"=>"October",
    "Nov"=>"November", "Dec"=>"December",

    "January"=>"January", "February"=>"February",
    "March"=>"March", "April"=>"April",
    "May"=>"May", "June"=>"June",
    "July"=>"July", "August"=>"August",
    "September"=>"September", "October"=>"October",
    "November"=>"November", "December"=>"December"
  );
?>
*/
<?php
  /*
  ** Get monthName array
  */
  include("data.php");

  print("Month 5 is " . $monthName[5] . "<br>\n");
  print("Month Aug is " . $monthName["Aug"] . "<br>\n");
  print("Month June is " . $monthName["June"] . "<br>\n");
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Development »




Environment
Error
Hash
Include
Locale
Math
Network
Output
Reflection
PHP Regular Expressions