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 :
- <?php
- Echo "<html>";
- Echo "<title>HTML with PHP</title>";
- Echo "<b>ExpertPHP 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.
- <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.
- <?php if(your condition) { ?>
- ... PUT HTML CODE ...
- <?php } ?>