Open In App

Different ways to write a PHP code

The full form of PHP is a Hypertext preprocessor. It was developed by Rasmus Lerdorf. It is a programming language for developing dynamic web applications and interactive websites. It is a server-side scripting language. It is used for establishing a connection between the front-end and database i.e., back-end.

Ways to run a PHP program:



Like this we have to save the PHP file 

After saving your code file into the htdocs folder follow the below steps.

A PHP code can be written in 3 ways



  1. Without any HTML markups
  2. Embedding HTML markups in PHP code
  3. Embedding PHP code in HTML.

1. Without any HTML markups:




<?php
    $a=10;
    $b=10;
    $c=$a+$b;
    echo("The addition of a and b is ". $c);
?>

Output :  

The addition of a and b is 20

2. Embedding HTML markups in PHP code:




<?php
    echo "<html>";
    echo "<h1> welcome </h1>" ;
    echo "</html>" ;
?>
  
   

Output:  

welcome

3. Embedding PHP code in HTML:




<html> 
<body> 
<?php 
    echo "Your first PHP code"
?> 
</body>
</html>

Output:

 Your first PHP code 

The most proficient way:


Article Tags :