Monday, February 15, 2016

Useing php for it

Before we proceed further, let us understand the steps to run a PHP program. Typically, a PHP code is embedded in an HTML page using tags "<?php" and "?>". Any code that sits between these two tags executes in the PHP context. Such a PHP code can be placed anywhere in an HTML page and can be placed any number of times as needed in an HTML page. Since PHP is an interpreter based language, there is no need to compile these programs!
We provide below a simple PHP "Hello World!" program. As mentioned above, we embed this program in an HTML file (let us call this file, "hello.php"). This program uses a PHP function "echo" to print the string "Hello World!"; when run, the output would get displayed on the browser. The line that contains the echo function is terminated by a semicolon and is often referred to as a statement.
 <!doctype html>
 <html>
 <body>
 <?php
 echo "Hello World! <br>";
 ?>
 </body>
 </html>
We need to follow a handful of steps to run this program.
First, we need to store this file at a location that is accessible to the web server (in Fedora/Red Hat Linux, the default location for web server is "/var/www/html"). Second, we need to ensure that the web server itself is running (in Fedora/Red Hat Linux, we can use "service httpd status" to see if the web server is running). If the web server is not running, then we need to start it (in Fedora/Red Hat Linux, we can use "service httpd start" to start the web server). Lastly, we need to load this file from a browser ("http://localhost/hello.php").
When we load this file, the web server would run the PHP code. Here is the output:

No comments:

Post a Comment