Web Development

PHP

PHP is a popular general-purpose scripting language that is especially suited to web development.

What is PHP?

  • PHP is an acronym for "PHP Hypertext Preprocessor".

  • PHP is a widely-used, open source scripting language.

  • PHP scripts are executed on the server.

  • PHP costs nothing, it is free to download and use.

What is a PHP File?

  • PHP files can contain text, HTML, CSS, JavaScript, and PHP code

  • PHP code are executed on the server, and the result is returned to the browser as plain HTML

  • PHP files have extension ".php"

What Can PHP Do?

  • PHP can generate dynamic page content

  • PHP can create, open, read, write, delete, and close files on the server

  • PHP can collect form data

  • PHP can send and receive cookies

  • PHP can add, delete, modify data in your database

  • PHP can restrict users to access some pages on your website

  • PHP can encrypt data

With PHP you are not limited to output HTML. You can output images, PDF files, and even Flash movies. You can also output any text, such as XHTML and XML.

A PHP script can be placed anywhere in the document.

A PHP script starts with <?php and ends with ?>.

The default file extension for PHP files is ".php".

A PHP file normally contains HTML tags, and some PHP scripting code.

Example

    <!DOCTYPE html>
    <html>
    <body>

    <h1>My first PHP page</h1>

    <?php
    echo "Hello World!";
    ?>

    </body>
    </html>

This example prints Hello World! on your browser screen. This php script uses a built-in PHP function "echo" to output the text "Hello World!" on a web page.

Windows users need to install WAMP which is the acronym for Windows Apache MySql PHP on their system to preview php pages. You can get it from http://www.wampserver.com/en/

Once WAMP is installed and you have created a simple php page you can preview it by opening a web browser and typing the address as localhost/ You need to save your php page at the location where you have installed WAMP Like, if you have installed it in c drive you need to go to the path c:\wamp\www\ and save your php pages here. If you create a folder within \www\ folder you need to mention that folder after you type in localhost in the web browser.

For example you have created a file example.php at the location c:\wamp\www\example\example.php then your address in the address bar of the browser would be localhost/example/example.php