Implementing functions and file inclusion in php


In today’s session we will study the php function and learn to implement file inclusion in php.

  • To study php function and file inclusion property follow the steps given below :

  1. Install Xampp server in your machine, if it is already installed then go to xampp folder .
  2. In this Xampp folder you will find htdocs folder.
  3. Create a new folder say s5 in this htdocs .

  4. In this s5 folder create an index.php file .

  5. To implement function write the following code in index.php
  6. Now in the same folder i.e s5 create a function.php file and open it with notepad++ .

  7. Now to implement function write the given code in function.php file :
  8. So now your notepad++ window will have the following look :

  9. Run the program by entering the following url in the address bar http://localhost/s5/index.php
  10. The output is shown below :
    • Now lets study the include and require functions :

    1. In the s5 folder create another folder say s6
    2. Now in this s6 folder create two files called as index.php and function.php .
    3. In the index.php write the code given below :
    4. In the index.php file we have included the function.php file , so now lets write the code in function.php file .
    5. Now start the server from your Xampp control pannel
    6. Now enter the following url in the browser to run your program : http://localhost/s5/s6/index.php
    7. Thus you will have the following output :

    8. Suppose now if incase in index.php file we include function1.php that does not exists then in the output it will display the error message and will not display its content but it will display the message from the index file.
    9. After executing the program you will have the following output :

    10. That is the content of index.php file still gets executed .
    11. But if we use require instead of include keyword it will display only error messages i.e it will not execute the index.php file which is shown below :
    12. V8

    • To study some of the built in functions in php follow the steps given below :

    1. In s5 folder create a new file called as builtfunction.php and write the following code in it :
    2. Save the file and enter the url in the browser as : http://localhost/s5/builtfunction.php
    3. Thus you will have the output as shown below :

      • Thus we have successfully studied the implementation of include , require and also some built in functions in php .


  1. I got this web page from my buddy who told me concerning this web site and at the moment this time I am visiting this
    web site and reading very informative articles or reviews at this place.

  2. I take pleasure in, result in I found just what I was having a look for.
    You’ve ended my 4 day lengthy hunt! God Bless you man.
    Have a nice day. Bye


Please enter your comment!
Please enter your name here