Jump to: navigation, search

Php include

From w3cyberlearnings

Contents

include

include keyword is used to include file content from another file. When include a file, need to have a file path. It is different for Window and Linux operating system on how to include a file.

Syntax

include 'filepath/file';

Note

  1. When you try to include a file from a different directory, you need to provide a file full path.

Example 1

file1.php

<?php
    echo "Hello world. <br/>";
    echo "Good to hear. <br/>";
?>

file2.php

<?php
        include 'file1.php';
        echo "In this main file";
?>

Output

Hello world.
Good to hear.
In this main file 

Example 2

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/>

mypage.php

<?php

include '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 world.


Related Links


Navigation
Web
SQL
MISC
References