Embedding PHP

Before understanding the embedded PHP we have to know that we can write our complete web applications in standalone PHP, but in most cases, PHP is embedded in HTML or XML file. Before Knowing Just because PHP is a scripting language & is used for making the page dynamic and process Logical tasks.

A source file can contain numerous lines of codes including PHP or non-PHP style. Working with PHP is quite different from HTML because the clients are unable to download the source code in PHP. Do you know that what happens when a user requests a PHP page? -The code in the requested file is processed by the server then it displays you the result 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 and what logic is used to process the page with the help of “view source”.

Example PHP code

            echo "Hello world using echo </br>";  
            ECHO "Hello world using ECHO </br>";  
            EcHo "Hello world using EcHo </br>";  

Embedding PHP in HTML

Have a look on given example :

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.

<title>Embed PHP within HTML tags</title>
Put here your HTML code
        // php code goes here
Back into normal HTML

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

<?php if(your condition) { ?>
<?php } ?>

about author

Suraj Kumar


I am a Freelance Software Developer and Website Designer

Leave a Reply

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