PHP require function
PHP require is same as PHP include function. But difference is that when you include a file with the include function and PHP cannot find it you will see an error message like the following:
failed to open stream: No such file or directory in
/home/websiteName/FolderName/filename.php on line 2 Warning: main(): Failed
opening 'filename.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in/home/websiteName/ on line 2
Program of require :
a.php File
<html>
<head>
<title>ADDITION OF TWO Numbers</title>
</head>
<body>
<?php
$no1=20;
$no2=10;
$no3;
$no3=$no1+$no2;
echo "<br>Addition is = $no3";
?>
Main file :
<?php require("a.php")?>
<p>This page requires a.php <br> !!! SEE IT !!!</p>
</body>
</html>
OUTPUT :
failed to open stream: No such file or directory in
/home/websiteName/FolderName/filename.php on line 2 Warning: main(): Failed
opening 'filename.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in/home/websiteName/ on line 2
Program of require :
a.php File
<html>
<head>
<title>ADDITION OF TWO Numbers</title>
</head>
<body>
<?php
$no1=20;
$no2=10;
$no3;
$no3=$no1+$no2;
echo "<br>Addition is = $no3";
?>
Main file :
<?php require("a.php")?>
<p>This page requires a.php <br> !!! SEE IT !!!</p>
</body>
</html>
OUTPUT :
0 comments:
Post a Comment