How Does PHP works and Embedding PHP in HTML

How Does PHP works and Embedding PHP in HTML

In this post we will give you information about How Does PHP works and Embedding PHP in HTML. Hear we will give you detail about How Does PHP works and Embedding PHP in HTMLAnd how to use it also give you demo for it if it is necessary.

How Does PHP works

Before knowing about the working of PHP you need to understand the difference between HTML and PHP.

The main difference between HTML and PHP is that PHP is used for making the page dynamic and it is the scripting language.

In HTML you write your code then deployed it and the user will download that page along with all the code.

The browser then interprets this code and shows the user the page as you planned for it. HTML code goes to the user same as it is and is interpreted by the browser.

But working with PHP is quite different because you don’t download the code in PHP. You need to know what happens when user request a PHP page? -The code in the requested file is processed by the server then you download the output of the code (in HTML form).

The main aim of working with PHP is to use the processing powers of the server to build the dynamic web pages. This means that if you click “view source” on a PHP page, you are not able to see the PHP codes you will see only HTML tags. Due to this you cannot see how a PHP page is made with the help of “view source”.



Embedding PHP in HTML


Normally you embed HTML outside of PHP tags but you can also echo HTML elements within PHP tags.

Have a look on given example :

  1. <?php
  2. Echo "<html>";
  3. Echo "<title>HTML with PHP</title>";
  4. Echo "<b>onlinecode Example</b>";
  5. //your php code goes here
  6. ?>
<?php  
Echo "<html>"; 
Echo "<title>HTML with PHP</title>"; 
Echo "<b>onlinecode Example</b>";  
//your php code goes here   
?>

As i told you that you can even embed php code within HTML Tags too, please have a look on given example.

  1. <html>
  2. <head>
  3. <title>Embed PHP within HTML tags</title>
  4. </head>
  5. <body>
  6. Put here your HTML code
  7. <?php
  8.     
  9.         // php code goes here
  10. ?>
  11. Back into normal HTML
  12. </body>
  13. </html>
<html>
<head>
<title>Embed PHP within HTML tags</title>
</head>
<body>
Put here your HTML code
<?php 
	
		// php code goes here
?>

Back into normal HTML

</body>
</html>

You can also put your html code within specific conditions of PHP.

  1. <?phpif(your condition){?>
  2. ... PUT HTML CODE ...
  3. <?php}?>
<?php if(your condition) { ?>
... PUT HTML CODE ...
<?php } ?>

Note : You can not run PHP code in .html files.

Hope this code and post will helped you for implement How Does PHP works and Embedding PHP in HTML. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  30  =  39

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US