亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

php file contains

PHP include files


PHP include and require statements

In PHP, you can insert a The contents of the file.

include and require statements are used to insert useful code written in other files into the execution flow.

and Require Except for different ways to deal with errors, they are the same in other aspects:

· Require generate a fatal error (e_compile_error). .

· include generates a warning (E_WARNING), and the script will continue to execute after the error occurs.

So if you want to continue execution and output the results to the user even if the included file is missing, then use include. Otherwise, in frameworks, CMS, or complex PHP application programming, always use require to reference key files to the execution flow. This helps improve application security and integrity in the event that a critical file is accidentally lost.

Including files saves a lot of work. This means you can create standard header, footer or menu files for all web pages. Then, when the header needs updating, you simply update the header include file.

Syntax

include 'filename';

or

require 'filename';

PHP include and require statements

Basic Example

Suppose you have a standard page header file named "header.php". To reference this header file in the page, please use include/require:

<html>
<head>
<meta charset="utf-8">
<title>php中文網(wǎng)</title>
</head>
<body>
 
<?php include 'header.php'; ?>
<h1>歡迎來到我的主頁!</h1>
<p>一些文本。</p>
 
</body>
</html>

Example 2

Suppose we have a standard menu file used in all pages.

"menu.php":

echo '<a href="/">主頁</a>
<a href="/html">HTML 教程</a>
<a href="/php">PHP 教程</a>';

All pages in the website should reference this menu file. The following is the specific approach:

<html>
<head>
<meta charset="utf-8">
<title>php中文網(wǎng)</title>
</head>
<body>
 
<div>
<?php include 'menu.php'; ?>
</div>
<h1>歡迎來到我的主頁!</h1>
<p>一些文本。</p>
 
</body>
</html>

Example 3

Suppose we have an include file ("vars.php") that defines variables:

<?php
$color='red';
$car='BMW';
?>

These variables can be used in calls In the file:

<html>
<head>
<meta charset="utf-8">
<title>php中文網(wǎng)</title>
</head>
<body>
 
<h1>歡迎來到我的主頁!</h1>
<?php
include 'vars.php';
echo "I have a $color $car"; // I have a red BMW
?>
 
</body>
</html>


Continuing Learning
||
<html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)</title> </head> <body> <?php include 'header.php'; ?> <h1>歡迎來到我的主頁!</h1> <p>一些文本。</p> </body> </html>
submitReset Code