Thursday 14 June 2018

First PHP Program - PHP training in chandigarh


Image result for PHP


First PHP Program

  • Your first PHP program
  • Running a PHP program

Your First PHP Program
PHP is a very simple scripting language. If you have read C language then you can easily create
 web applications in PHP. So far, you have learned about PHP tags. Let's now try to make a simplest
 program in PHP and understand it.

However PHP can be embedded with HTML. But you can also create a program of only PHP.
 The following is a pure PHP program.
Because I have stored the php file in the directory, so it will only access it by the name of the directory.

<?php

echo "Hello Reader <br>";

echo "Welcome to Best Hindi Tutorials";

?>

The <? Php opening tag has been used first in the above program. As you know, the PHP code 
is always written between <? Php and?> Tags. Therefore it is necessary to define these tags before
 writing the main PHP code.

The echo function has been used 2 times after the PHP opening tag. This function is used in PHP
 to print values of string messages and variables. You can also define HTML tags in this function.
 As in the example given above, the tag tag is defined, which is used for the line break.

This is a very simple example. This example prints Hello Reader and Welcome to Best Tutorials
 messages as an output.



Running a PHP Program

You can not execute a PHP program like any HTML program. Because PHP is a server side 
 scripting language, PHP is executed by the server.

Before telling to execute the PHP program, assuming that you have installed XAMPP in your 
computer, and you have started the Apache server with the XAMPP control panel.

XAMPP is a software package that provides services such as PHP interpreter, Apache server and 
MySQL to develop in PHP.

If you have not yet installed XAMPP, please install XAMPP after following the tutorial of PHP
 installation.

Before running any PHP program, your XAMPP control panel should have this situation as follows.
 CBitss Provide Best php training in chandigarh . CBitss Is Ine Of The Best training institute in
 chandigarh . for More Information visit our website

XAMPP-Control-Panel

PHP files execute by server, so all PHP files are stored on the server. XAMPP installs the local 
server in your computer so that your computer becomes the server.

Because you are still learning to create web applications in PHP, you will work on the local server. 
Once you learn well, you can work on the live server too.

Whether the local server is used or the live server concept is the same. You store your files in a 
directory of the server. Later when the web browser requests for that file then the server executes
 them and the result is displayed in the browser.

There are many applications available for uploading files to Live Server. FileZilla service is highly used
with PHP for this purpose. But because you will be working on the local server now, you do not have to
 use it.

The directory of the local server created by XAMPP will be found in the drive named XAMPP inside
 the name of the htdocs. You will store all your files in this directory.

Running-PHP-Program-1

In this directory, you can also store your PHP files directly or you can create any directory by the 
name of your project, and also store PHP files inside it.

As an example to explain to you, I have created a directory named after Best Hindi Tutorials.

Running-PHP-Program-2

You will store all your PHP files with the .php extension and save it in this folder. For example, I have
 saved the example created above the name of First_PHP_Program.php.

Running-PHP-Program-3

So far, you have learned to create a PHP file and store it in the server directory. To execute this file
 you will first open the window of your browser.

After this you will type localhost in the browser window. As soon as you press enter, you will have a 
welcome page show of XAMPP, this means your server is working properly. If you do not show this 
page then you either have not started the server or you have not properly installed the server.

Running-PHP-Program-4

To execute the PHP file, you write the name of that file by putting forward slash in front of localhost. 
If you have created and stored the file in the directory then by putting forward slash after localhost, 
you will first type the name of the directory followed by the forward slash and name the file. Its syntax 
is being given below.

localhost / directory Name / fileName.php

Because I have stored the php file in the directory, so it will only access it by the name of the directory.

Running-PHP-Program-5

As soon as you press enter, your PHP file will execute. If there is no mistake in your coding then you
 will normally be output show.

Running-PHP-Program-6

Note: PHP files are accessed through browser because PHP files are stored on the client machine
 not on the server. However in this case both client and server are both the same computer.

0 comments:

Post a Comment