How can we write a script in PHP

You are currently viewing How can we write a script in PHP

How can we write a script in PHP

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.

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 data-rsssl=1>
<h1>Way to write PHP Script</h1>
<?php
echo "Hello World!";
?>
</body>
</html>

				
			
				
					Output:-  

Way to write PHP script
Hello World!


				
			

Ways to run a PHP program:

  • Save the file with any name followed by a .php extension.
  • Save the file in the XAMPP location of the file structure.
  • If the XAMPP is installed in local disk C, then we have to save the file in C:\xampp\htdocs.
  • After saving y\our code file into the htdocs folder follow the below steps.
  • Open XAMPP control panel.
  • Start Apache and MySQL servers.
  • Go to any browser and type localhost/filename.php in the search box.
  • Our PHP script show output on web browser.

Leave a Reply