{"id":64,"date":"2023-05-06T03:00:56","date_gmt":"2023-05-06T03:00:56","guid":{"rendered":"https:\/\/itnotes.apjsoftwares.com\/?p=64"},"modified":"2023-05-06T03:00:56","modified_gmt":"2023-05-06T03:00:56","slug":"write-a-short-note-on-include-and-require","status":"publish","type":"post","link":"https:\/\/itnotes.apjsoftwares.in\/index.php\/2023\/05\/06\/write-a-short-note-on-include-and-require\/","title":{"rendered":"Write a short note on include () and require ()."},"content":{"rendered":"\n<p><strong>include() function:\u00a0<\/strong><\/p>\n\n\n\n<p>This function is used to copy all the contents of a file called within the function, text wise into a file from which it is called. This happens before the server executes the code.<\/p>\n\n\n\n<p>Example: This example is using the include() function in PHP.<\/p>\n\n\n\n<p>&lt;?php<\/p>\n\n\n\n<p>\/\/ File to be included<\/p>\n\n\n\n<p>echo &#8220;Hello GeeksforGeeks&#8221;;<\/p>\n\n\n\n<p>?&gt;<\/p>\n\n\n\n<p>Now, try to include this file into another PHP file index.php file, and will see the contents of both the file are shown.&nbsp;<\/p>\n\n\n\n<p>&lt;?php<\/p>\n\n\n\n<p>include(&#8220;even.php&#8221;);<\/p>\n\n\n\n<p>echo &#8220;&lt;br&gt;Above File is Included&#8221;<\/p>\n\n\n\n<p>?&gt;<\/p>\n\n\n\n<p>Output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"169\" height=\"47\" src=\"https:\/\/itnotes.apjsoftwares.com\/wp-content\/uploads\/2023\/05\/image-5.png\" alt=\"\" class=\"wp-image-65\"\/><\/figure>\n\n\n\n<p><strong>require() function:&nbsp;<\/strong><\/p>\n\n\n\n<p>The require() function performs the same as the include() function. It also takes the file that is required and copies the whole code into the file from where the require() function is called.<\/p>\n\n\n\n<p>Now, if we try to include this file using require() function into a web page we need to use an index.php file. We will see that the contents of both files are shown.<\/p>\n\n\n\n<p>&lt;?php<\/p>\n\n\n\n<p>require(&#8220;even.php&#8221;);<\/p>\n\n\n\n<p>echo &#8220;&lt;br&gt;Above File is Required&#8221;<\/p>\n\n\n\n<p>?&gt;<\/p>\n\n\n\n<p>Output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"164\" height=\"48\" src=\"https:\/\/itnotes.apjsoftwares.com\/wp-content\/uploads\/2023\/05\/image-6.png\" alt=\"\" class=\"wp-image-66\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>include() function:\u00a0 This function is used to copy all the contents of a file called&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[],"_links":{"self":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/64"}],"collection":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/comments?post=64"}],"version-history":[{"count":1,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/64\/revisions"}],"predecessor-version":[{"id":67,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/64\/revisions\/67"}],"wp:attachment":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/media?parent=64"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/categories?post=64"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/tags?post=64"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}