The PHP script is used to make a website dynamic.
The code must be written within the defined PHP tags otherwise it would not execute.
1. PHP Tags
All PHP codes are specified within
<?php ?> tag.
<?php // code ?>
<html> <body> <?php echo "PHP CODE"; ?> </body> </html>
2. Include and require
With include and require statement, you can include existing PHP files in your file.
Syntax – include
Syntax – require
Both statement use for including file but the only difference is –
The require statement trigger FATAL ERROR if a file included more than once but the include statement doesn’t.
In the example, I have included
config.php file on the page.
config.php file contains PHP code.
After including the PHP file you can use functions, variables of the including file in your page.
<?php include "config.php"; ?> <html> <body> <?php echo "PHP CODE"; ?> </body> </html>
Specify your PHP code between
<?php ?> tags in the webpage. You can use include and require statements to embed existing PHP files.