HEMANT SONKER'S BLOG

Tuesday, January 13, 2009

Tutorials on php:Day 2

BUILDING BLOCKS IN PHP

Variables
A variable is a special container that you can define, which will then contain a value you specify. For example a number, string, object, array or boolean.

Constants
If you want to work with a value that needs to remain unchanged, you can define and use a constant variable. This isdifferent to a variable as variables offer a flexible way of storing data as you can change their values and type of data they hold.

Globals and Superglobals
In addition to global declerations aof your own, PHP has built in predefined variables called superglobals. These are always present and the value they hold can be available in all your scripts.

Predefined Constants
PHP provides some built in constants for you. For example __FILE__ returns the name of the file that PHP is using. __LINE__ returns the line number that php is running and PHP_VERSION returns what php version your script is being run on.

Data types
Different types of data will take up different amounts of memory and may then be treated different in the script that you write. PHP will automatically determine the data type for the variable the time data is assigned to it. Some examples of data types are boolean, integer, float, string, object, array, resource, null (an uninitialized value).

The Assignment operator
The equals sign (=) is an assignment operator and will put the value on the right hand site and assign it to the left hand side.

Arithmetic Operators
Arithmetic operators perform mathematic operations on the values you want them to (providing they are a number). Some examples are addition (+), subtraction (-), division (/), multiplication (*), modulus (%). You can increment numbers by putting two addition operators nxet to eachother like so: (++). PHP provides combined operators which allow you to transform the left hand operand and return a result, while also modifying the original value of the variable. To return 'x' and and 5 to 'x' on the same line you would use '$x +=5.'

The Concatanation Operator
The concatanation operator allows you to join strings together. It is represented by a single period (.). Expressions, calculations and variables can also be concataned and the data type returned will aloways be that of a string.

The Comparison Operator
Comparison operators perform comparative tests using their operands and return the boolean value true if the test is succesful and false if it false. Some examples are Equivalence (==), Non-equivalence (!=), greater than (>), less than or equal to (<=). You can use logical operators such as Or (||), and (&&) and Not (!) to extend comparisons using the if() statement.

Tuesday, January 6, 2009

Tutorials on php:Day 1

Hi guys, writing after couple of months.This time i am learning php and would like to share what i am learning right now.

What is PHP? and why PHP?

*PHP (recursive acronym for "PHP: Hypertext Preprocessor") is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.

*PHP is mainly focused on server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynamic page content, or send and receive cookies.

*PHP can be used on all major operating systems, including Linux, many Unix variants (including HP-UX, Solaris and OpenBSD), Microsoft Windows, Mac OS X, RISC OS, and probably others.

*PHP has also support for most of the web servers today. This includes Apache, Microsoft Internet Information Server, Personal Web Server, Netscape and iPlanet servers, Oreilly Website Pro server, Caudium, Xitami, OmniHTTPd, and many others.

*PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.)
*PHP is free to download and use


What is a PHP File?

*PHP files can contain text, HTML tags and scripts
* PHP files are returned to the browser as plain HTML
* PHP files have a file extension of ".php", ".php3", or ".phtml"

What is MySQL?

* MySQL is a database server
* MySQL is ideal for both small and large applications
* MySQL supports standard SQL
* MySQL compiles on a number of platforms
* MySQL is free to download and use

PHP + MySQL


* PHP combined with MySQL are cross-platform (you can develop in Windows and serve on a Unix platform)

Where to Start?

To get access to a web server with PHP support, you can:

* Install Apache (or IIS) on your own server, install PHP, and MySQL
* Or find a web hosting plan with PHP and MySQL support


PHP - What's it do?


It is also helpful to think of PHP in terms of what it can do for you. PHP will allow you to:

* Reduce the time to create large websites.
* Create a customized user experience for visitors based on information that you have gathered from them.
* Open up thousands of possibilities for online tools.
* Allow creation of shopping carts for e-commerce websites.

What You Should Know

Before starting this tutorial it is important that you have a basic understanding and experience in the following:

* HTML - Know the syntax and especially HTML Forms.
* Basic programming knowledge - This isn't required, but if you have any traditional programming experience it will make learning PHP a great deal easier.