PHP Tutorial - Introduction & Data types !!

Started by ram, Jul 21, 2008, 10:32 AM

Previous topic - Next topic

ram

Hi [you],

PHP Tutorial - Introduction

In this tutorial you will learn about PHP - Introduction to PHP, What you should already know? What's PHP? What's the difference between PHP and HTML? When to use PHP? What makes PHP a choice among the other scripting languages?

What you should already know?

    * You have to have good knowledge of the following before you can proceed:
    * HTML
    * JavaScript

What's PHP?

    * PHP stands for Hypertext Preprocessor.
    * PHP scripts run inside Apache server or Microsoft IIS.
    * PHP and Apache server are free.
    * PHP code is very easy.
    * PHP is the most used server side scripting language.
    * PHP files contain PHP scripts and HTML.
    * PHP files have the extension "php", "php3", "php4", or "phtml".

What's the difference between PHP and HTML?

    * HTML files are requested by browser, and returned by server.
    * PHP files are requested by browser, and executed by the server to output a plain HTML that is returned to the browser.

When to use PHP?

    * Creating Web pages that contain dynamic contents.
    * esponding to HTML forms.
    * Accessing databases.
    * Securing data.

What makes PHP a choice among the other scripting languages?

    * PHP is easy to learn.
    * PHP is free.
    * PHP can run on Windows and Unix servers.
    * PHP is very fast.

PHP Tutorials - Data Types

In this PHP Tutorial you will learn about PHP Data Types viz. Numeric values, String values, Boolean values, Arrays, Objects and NULL.

Numeric values:

There are two numeric values in PHP, they are:

1. integer: Integer numbers don't have floating point, for example, 5, 12, 1567

2. real: or floating point numbers, real number has a floating point, for example, 2.3

There are three ways to represent the numeric values:

1. base 10 numbers: They are represented using digits from 1 to 9, with an optional (.) for floating point if the value is real.

2. base 8 numbers: They are represented by preceding the number by zero '0', and it only permits the digits from 0 to 7, example 023, which is the same as 19

3. base 16 numbers: They are represented by preceding zero and x '0x', and it permits the digits from 0 – 9 and characters from 'A' to 'F', for example, 0x3f, which is the same as 63

String values:

String values are sequence of characters, included in a single quote or double quotes, for example,

    'This is a string'.

The value inside the quotes are not modified, so if you want to use quotes inside the string, then they have to be escaped, we escape characters in PHP by using backslash,

for example,

    'She wrote: \'PHP is easy to learn\''.

The quote is not the only special character that can be escaped, other characters that can be escaped are:

    \n Line feed
    \r Carriage return
    \t Tab
    \\ Backslash
    \" Double quotes

For example,

    "This is \n a string", this will evaluate to:

    This is
    a string

Boolean values:

Boolean values are true or false, also 0 and empty string evaluates to false, and any numeric value rather than zero, or a string that is not empty evaluates to true.

Arrays:

An array is a collection of elements of heterogeneous type, arrays will be explained later.

Objects:

An object is a collection of data and code, you will learn about Objects later in a seperate tutorial.

NULL:

NULL means no value. It does not contain any meaningful data.