08 Jul PHP include Statement
The PHP include statement also includes a file in your PHP code, but it has a benefit over PHP require statement. While executing the include() statement, if the file isn’t found, then the script won’t stop. It will continue, unlike the require statement, which returns an error if the file isn’t available.
Here’s the syntax,
1 2 3 |
include 'filename'; |
Now, we will learn with an example. We have two files, credits.php, and index.php.
Here’s the code for index.php, wherein we’ve included the credits.php file using the include
1 2 3 4 5 6 7 8 9 10 11 12 |
<html> <body> <h1>Studyopedia</h1> <p>One stop destination for learning!.</p> <?php include credits.php';?> </body> </html> |
Here’s the code for credits.php. We’re adding a single line here for site credits.
1 2 3 4 5 |
<?php echo "<p>Powered by WordPress! </p>"; ?> |
Here’s the output, which shows the site credits,
No Comments