Implementing functions and file inclusion in php

3
10112

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. v1

  5. In this s5 folder create an index.php file .
  6. 1

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

  10. Now to implement function write the given code in function.php file :
  11. So now your notepad++ window will have the following look :
  12. v3

  13. Run the program by entering the following url in the address bar http://localhost/s5/index.php
  14. The output is shown below :
  15. v5

    • 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. v6

    9. 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.
    10. After executing the program you will have the following output :
    11. v7

    12. That is the content of index.php file still gets executed .
    13. 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 :
    14. 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 :
    4. v9

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

3 COMMENTS

  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

LEAVE A REPLY

Please enter your comment!
Please enter your name here