Php require
From w3cyberlearnings
Contents |
require
require keyword uses to include a file, it is similar to include() function, the only different is that require will generate an error when it fails to include a file, and it makes the program to stop running.
Syntax
require "filepath/filename.php"; require "filepath/textfile.txt";
Note
This function produce a fatal E_COMPILE_ERROR level error when failed to include a file.
Example 1
mylist.txt
Leader leads our road path.<br/> Mother cooks our dinner.<br/> Father waste our cloths.<br/> Mother and Father lead our path.<br/> If leader leads our road path,<br/> and Mother and Father is a leader.<br/> Both of them lead our path.<br/>
test.php
<?php require 'mylist.txt'; echo 'In the word'; ?>
Output
Leader leads our road path. Mother cooks our dinner. Father waste our cloths. Mother and Father lead our path. If leader leads our road path, and Mother and Father is a leader. Both of them lead our path. In the word
Example 2
header.php
<?php echo '<p>Welcome to my program!</p>'; echo '<hr width="100%"/>'; ?>
<?php echo '<hr width="100%"/>'; echo 'copyright 2012'; ?>
main.php
<?php require "header.php"; echo "This is in main page<br/>"; require "footer.php"; ?>
Output
Welcome to my program!
This is in main page
copyright 2012
Related Links
- require
- include
- require_once
- include_once
- goto