Saturday, May 19, 2012

php step by step


Getting Started with PHP


first you want to setup your pc for the run  php go this
 http://iphonik-php.blogspot.com/p/abc.html

PHP Basics
Basic PHP Syntax
PHP is server side scripting language. As start point, we just execute this script this.
First Example Program
<html>
<head>
<title>Hello World</title>
</head>
<body>

<?php
        echo " Hello World";
        ?>

</body>
</html>

Note:
Instead of echo, we can use even print.
“echo” is not a function, but it’s a language construct. Valid with and without parenthesis.
Publish PHP scripts on Apache server
  •  Hope you know where to save the PHP file.
 If not, go to your xampp installed partition on your computer.

  • ex. if you installed partition is C then Apache  document root is "C:\xampp\htdocs" then create directory "Test"
  •  open "Notepad" and write this example and save this in your "Test" directory as “first.php”
 This example Browser View 

open browser and go   http://localhost/first.php or  http://127.0.0.1/first.php

How PHP works?
You need a web server that works in conjunction with PHP? You need this because the PHP code has to be executed, the PHP interpreter handles this. The web server is set up to recognise certain extensions as a PHP document, say .php.

v  Internet browser requests "index.php" from WEB SERVER
v  WEB SERVER receives request.
v  WEB SERVER checks "what type of document is this?"
v  WEB SERVER invokes the PHP engine and passes it the contents of "index.php".
v  PHP Engine checks the document and anything between <?php and ?> is converted to HTML output.
v  PHP returns the HTML output to the WEB SERVER.
v  WEB SERVER sends document to internet browser.

PHP code does not have to be compiled (converted to an executable program) before hand, when the web server passes PHP document, it is then compiled on-the-fly (or interpreted), executed, checked for errors and then returned to the web server. So what is sent to the client (the person requesting the document) is not PHP code at all, it is the output of the PHP code.

<html>
    <head>
        <title>Hello World</title>
    </head>
    <body>

        <?php
        echo " Hello World";
        ?>

    </body>
</html>
<html>
    <head>
        <title>Hello World</title>
    </head>
    <body>
            <p> Hello World</p>
    </body>
</html>
Php Script
Html page

All the PHP code did was to output "<p>This is my first PHP script.</p>", when PHP sends the output from the script back to the web server the above is what remains. If a user views the source of a PHP page in a text editor they will not see PHP code, all they will see is the output of that code.









Form Processing with PHP

Form Processing with PHP PHP "superglobals" Several predefined variables in PHP are "superglobals", which mean...