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

<?php  
            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 :

<?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 } ?>

about author

Suraj Kumar

surajkumarkhg8844@gmail.com

I am a Freelance Software Developer and Website Designer

Leave a Reply

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