Php
Whenever anyone is learning PHP, the most common questions that first come up are: What is PHP? And how does it work?It is precisely these questions we will look at in this lesson. It's a big help to understand such basics related to PHP before you start developing you own PHP pages. Such basic understanding will increase the speed of learning significantly.
So, let's get started!
What is PHP?
PHP was originally an acronym for Personal Home Pages, but is now a recursive acronym for PHP: Hypertext Preprocessor.
PHP was originally developed by the Danish Greenlander Rasmus Lerdorf, and was subsequently developed as open source. PHP is not a proper web standard - but an open-source technology. PHP is neither real programming language - but PHP lets you use so-called scripting in your documents.
To describe what a PHP page is, you could say that it is a file with the extension .php that contains a combination of HTML tags and scripts that run on a web server.
Php is a widely use open source general-purpose scripting laguage that is especially suited for web development and can be embaded into html
How does PHP work?
The best way to explain how PHP works is by comparing it with standard HTML. Imagine you type the address of an HTML documens:
Why Php?????
1. PHP runs on different operating system such as Windows, Linux, Unix, etc.
2.PHP is easy and fast to learn and runs efficiently on the server side.
3.PHP is compatible with almost all web servers used today such as IIs, Apache, and so on .
4. PHP supports many databases such as MySQL, Oracle, PostgreSQL etc.
5.PHP with MySQL database and Apache Server is a very good and popular combination.
6.PHP combined with MySQL are cross-platform.
7.PHP is the widely-used, free, and efficient alternative to competitors such as Microsoft's ASP and Sun Microsystems JSP.
8.PHP is perfectly suited for Web development and can be embedded directly into the HTML code.
9.PHP is often used together with Apache (web server) on various operating systems.
10.It can be also used with Microsoft's IIS on Windows.
11.Php is easy to learn and runs efficiently on any compatible web server.
Uses of PHP:
PHP performs system functions, i.e. from files on a system it can create, open, read,
write, and close them.
PHP can handle forms, i.e. gather data from files, save data to a file, thru email you can
send data, return data to the user.
You add, delete, modify elements within your database thru PHP.
Access cookies variables and set cookies.
Using PHP, you can restrict users to access some pages of your website.
It can encrypt data.
Characteristics of PHP
Five important characteristics make PHP's practical nature possible:
- Simplicity
- Efficiency
- Security
- Flexibility
- Familiarity
Starting tags of php
<?php ?> // standard tags
<? ?> // short tags, need short_open_tag enabled in php.ini
<% %> // asp tags, need asp_tags enabled in php.ini
<script language="php"> </script> // case insensitive
First Program in PHP:
To get a feel for PHP, first start with simple PHP scripts. Since "welcome to php" is an essentialexample, first we will create a friendly little "welcome to php" script.
As mentioned earlier, PHP is embedded in HTML. That means that in amongst your normal HTML
(or XHTML if you're cutting-edge) you'll have PHP statements like this:
<html>
<head>
<title>uk</title>
<body>
<?php echo "welcome to php";?>
</body>
</html>
OUTPUT
welcome to phpIf you examine the HTML output of the above example, you'll notice that the PHP code is not
present in the file sent from the server to your Web browser. All of the PHP present in the Web
page is processed and stripped from the page; the only thing returned to the client from the
Web server is pure HTML output.
All PHP code must be included inside one of the three special markup tags ate are recognised by
the PHP Parser.
<?php PHP code goes here ?>
<? PHP code goes here ?>
<script language="php"> PHP code goes here </script>
Most common tag is the <?php...?> and we will also use same tag in our tutorial.
From the next chapter we will start with PHP Environment Setup on your machine and then we
will dig out almost all concepts related to PHP to make you comfortable with the PHP language.
PHP Environment Setup
In order to develop and run PHP Web pages three vital components need to be installed on your
computer system.
Basic Tag of php
ASP-style tags mimic the tags used by Active Server Pages to delineate code blocks. ASP-style
tags look like this:
<%...%>
To use ASP-style tags, you will need to set the configuration option in your php.ini file.
HTML script tags:
HTML script tags look like this:
<script language="PHP">...</script>
Commenting PHP Code:
Comment
A comment is the portion of a program that exists only for the human reader and stripped out
before displaying the programs result. There are two commenting formats in PHP:
Single-line comments: They are generally used for short explanations or notes relevant to the
local code.
Single Line Comments
<?# This is a comment, and
# This is the second line of the comment
// This is a comment too. Each style comments only
print "An example with single line comments";
?>
Multi-lines comments: They are generally used to provide pseudocode algorithms and more
detailed explanations when necessary. The multiline style of commenting is the same as in C.Here are the example of multi lines comments.
<?
/* This is a comment with multiline
Author : Mohammad Mohtashim
Purpose: Multiline Comments Demo
Subject: PHP
*/
For more on php visit php-tutorial