Sunday, 27 May 2012

A sample Addition program

A sample PHP addition program

<?php
$a=10;
$b=5;
$c=$a+$b;
echo $c;
?>



output will be 15

Explanation:

line 1: opening of PHP script
line 2: $a=10; PHP uses $ sign to declare variables and does not require Data type to be declared.
    suppose:
     if you declare $a=10; php understands that this of type integer
     if you declare $a=10.5; php understands that this of type floating value
    if you declare $a='This is PHP tutorial'; php understands that this of type string and so on...
    and of course semicolon(;) is required to terminated the statement.
line 3:$b=5; same as above explanation.
line 4: is an expression to add two values and take that value in $c variable
line 5: outputs the Addition by using echo statement followed by $c; variable.
line 6: ends the PHP script.  
        

A sample PHP program


Create a file named hello.php and put it in your web server's root directory (DOCUMENT_ROOT) with the following content
* DOCUMENT_ROOT in cae of xampp is "c:/xampp/htdocs". PHP programs should be saved in htdocs folder



Example #1 Our first PHP script: hello.php
<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php echo '<p>Hello World</p>'?>
 </body>
</html>

Use your browser to access the file with your web server's URL, ending with the /hello.php file reference. When developing locally this URL will be something like http://localhost/hello.php or http://127.0.0.1/hello.php but this depends on the web server's configuration. If everything is configured correctly, this file will be parsed by PHP and the following output will be sent to your browser:


output :"Hello World"


and the html source code would look like this:

<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <p>Hello World</p>
 </body>
</html>

Now an Explanation of our Hello.php program
line1: opening of html tag
line 2: opening of head tag
line 3: opening and closing of title tag with a tilte to appear on tab.
line 4: opening of body tag
line 5: starts with <?php then echo opening of paragraph tag and some text and closing of paragraph tag and then closing of ?>
Note: 1)every PHP program must start with <?php must end with ?>.
          2)The statements written inside the "<?php...... ?>" will be executed by php interpreter.
          3)In the above example you can see echo statement echo is used to output the result, moreover a html tag can also be sent as output to the browser with echo statement.
 Example :       echo '<p>Hello World</p>';


line 6: closing of body tag
line 7:closing of html tag
        

Friday, 25 May 2012

Installing XAMPP


Install XAMPP
Now that we have downloaded the XAMPP file, the next step is to install it.
Note - If you are running the Skype VOIP application, or if you are running IIS Server, you will need to exit them before proceeding. Apache cannot start as a service if Skype or IIS is also running though when XAMPP is not in use, you can exit XAMPP to use Skype or IIS.
1.Double-click on the file that we downloaded in order to run it.
2.Select the language you wish the installation process to use, and click Ok.


3.A welcome message will display. Click Next.
4.Next, we have to choose a place to install XAMPP. This book assumes that XAMPP is installed in c:\xampp. Choose a directory and select Next. Note that for Windows Vista, Apache Friends recommends not installing XAMPP into your c:\Program Files\ folder.
                                                              
5.In the next screen, we are prompted to install Apache and MySQL as services. Doing this will save us from having to start XAMPP every time we switch on our computer (and will allow other applications you may have, such as Skype, to run simultaneously), so check those boxes (but do leave the FileZilla box unchecked). Then
click Install.

6. XAMPP will then install. At one point, a command-line window will open; do not be alarmed this is normal! After the installation is complete, we will get a message indicating so. Click Finish.
7.Next, we are prompted to start the XAMPP control panel, which can also be opened by selecting Start | All Programs | XAMPP | XAMPP Control Panel, or by running c:\xampp\xampp-control.exe. Select Yes.



Now  you have sucessfully Installed the Xampp server.



Installing a web server


Php Programs Run on a Web server for example: Apache etc.
I would Recommend you XAMPP which contains Apache, MYSQL , Filezilla, Mercury, Tomcat.
In this Software There's also a MYSQL server for creating Databases and Tables which we can make it interact with our PHP scripts. of course There are Other packages like WAMPP, LAMP etc.

If you are using Windows Operatinf system then click here to download it and install with common configurations or you can download from the website (apache friends).