PHP Include and Require Funcation

WBOY
發布: 2024-08-29 12:56:39
原創
136 人瀏覽過

The PHP Include and Require statement helps in taking all the code/text/markup code which exists in the specific PHP file/doc and then it will copy the code text from the file included to the file where Include statement of the PHP is used. If the script which contains in the include.php file is copied to the original PHP file then the output will be the same as mentioned in the above description. To differentiate the big project’s programs one must need to create the different programs. To assemble all those files in one, one should use include or require statement in the original index or other PHP Program File.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax:

include("Enter File Path – Pavan Kumar Sake"); or include "Enter File Path – Pavan Kumar Sake"; require("Enter the File Path – Pavan Kumar Sake"); or require "Enter the File Path – Pavan Kumar Sake";
登入後複製

How does include and require work in PHP?

This statement will help in allowing the code which present in the other.PHP file which contains in a specific original PHP file. It returns the same output if we used the code present in a specific.PHP file code in our original PHP file directly. By using the include() or the require() function/statement one can save lots and lots of time and can reduce the workload too by including the files/content.

Just store some code in a specific.PHP file and then include it in any other PHP file/files whenever you needed just with the help of the include() or require a () statement as mentioned in the Syntax section. Instead of typing the whole PHP code many times when required, one can enter the code using the include() statement multiple times. For example, we can include the HEADER.PHP, MENU.PHP, FOOTER.PHP files in one main INDEX.PHP file to include the code present in those.PHP files in the INDEX.PHP file.

Examples to Implement PHP Include and Require

Below are the examples mentioned:

Example #1

This is the example of implementing the PHP Include statement. At first html tags are created and then in the title tag, some string content is entered. This will be visible on the browser tab when the cursor is placed. Then paragraph “

” tag is used to enter some content and then include statement is used to import HEADER1.PHP file’s content in the index program. Then paragraph tags are used for some content display and then again include statement is used to import MENU1.PHP file’s content. Then header tags and paragraph tags are used with some content in it. Then again PHP includes statement is used to import content from the FOOTER1.PHP FILE. Then the html tag is closed. Include statements of this program that will help in getting the other 3 PHP files content.

Syntax of INDEX.PHP FILE :

   Sake Pavan Kumar DOC - Implementing include() function  

This content is from the Header1 PHP File ::

This content is from the Menu1 PHP File ::

Welcome to Our Blog/Website!

Hi, This is Pavan Kumar Sake. I am a Content Writer, Blogger, Engineer, Physics Nerd, Tech Enthusiast. This content is from the original file only

This content is from the Footer1 PHP File ::


登入後複製

Syntax of HEADER1.PHP FILE:

  

登入後複製

Syntax of MENU1.PHP FILE:

  

登入後複製

Syntax of FOOTER1.PHP FILE:

  

登入後複製

Output:

PHP Include and Require Funcation

Example #2

This is the example of implementing the REQUIRE STATEMENT OF PHP Programming Language. Here instead of using the include statement “include() statement” we are using the required statement “require() statement”. Here also just like the example 1, most of the content is the same with the same HTML tags, and some of the string output content also the same but the difference is only the usage of the REQUIRE STATEMENT OF PHP. Check out the output for a better understanding.

Syntax of INDEX.PHP:

   Sake Pavan Kumar DOC - Implementing include() function  

This is the PHP program which is implemented using the REQUIRE STATEMENT

This content is from the Header1 PHP File ::

This content is from the Menu1 PHP File ::

Welcome to Pavan Kumar Sake Website!

Hi, This is Pavan Kumar Sake. I am a Content Writer, Blogger, Engineer, Physics Nerd, Tech Enthusiast. This content is from the original file only

This content is from the Footer1 PHP File ::


登入後複製

Syntax of HEADER1.PHP:

  

登入後複製

Syntax of MENU1.PHP:

  

登入後複製

Syntax of FOOTER1.PHP:

  

登入後複製

Output:

PHP Include and Require Funcation

Advantages to PHP Include and Require

The PHP include and require a statement that is having a huge advantage in using to develop static and dynamic web pages according to our needs. This PHP statement reduces the workload and helps in saving lots of time most of the time. If there is a need to enter some type of code in a specific file or in different types of PHP files one must type each and every time and then if we use include() or require() whenever or wherever you want we can save the time of typing and also can reduce the workload. We can use separate PHP files for each and every web development section.

Conclusion

I hope you learned what is the definition of PHP Include and Require statement along with its syntax and explanation, How to Include and to Require works in PHP along with various examples, Advantages of the statements, etc. to understand the PHP Include or require statements better and so easily.

以上是PHP Include and Require Funcation的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
php
來源:php
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!