Thursday, June 27, 2013

include php in html

include php in html
In this lesson we will talk about include function and how to use it, so let's go
First include function are used to insert a php file into an html file or another php file and it will be executed with the rest of the code in the same file, let's do an example
<?php
$a=15;
$b=10;
if($a==$b){
include ('h1yes.php');
}
else{
include ('h1no.php');
}
?>

The code in the h1yes.php is
<?php
echo "<h1> YES</h1>";
?>

The code in the h1no.php is
<?php
echo "<h1> NO </h1>";
?>

The files must be in the same directory in this example

include php in html

As we can see the values ​​of variables are not equal so we will see no on the screen

include php in html

So this is how to include php in html, there is an other function to include php in html and it's the require function and the difference between it and the include function is that the code will be stop if there is an error in finding the file with the require function.

But with the include function the code will be continue even if there is an probleme to finding the file included 
That was the include php in html lesson, See you next time.

Share This!



No comments :

Post a Comment