Topics covered in this snack-sized chapter:

Introduction

How PHP Helps?

How PHP Works?

Simple Example of PHP Program

What Can PHP Do?

Advantages of PHP

Disadvantages of PHP

Introduction 

"PHP" is an acronym that stands for "PHP: Hypertext Preprocessor".

The word "Preprocessor" means that PHP makes changes before the HTML page is rendered.

A Simple PHP Architecture

PHP is basically used for developing web based software applications.

PHP is a server-side language. 

PHP was originally designed to generate dynamic web content.

It is equally suitable for generating and parsing XML content.

It is used to manage dynamic content, databases, session tracking, even build entire e-commerce sites.

How PHP Helps?

It reduces the time needed to create large websites.

It creates a customized user experience for visitors .

It opens up thousands of possibilities for online tools.

It allows creation of shopping carts for e-commerce websites.

How PHP Works?

The purpose of a web server is to send HTML to the browser.

The most common use of web server is to host websites, but there are other uses such as gaming, data storage or running enterprise applications.

PHP works closely with a web server, which enables you to build interactive and dynamic web pages.

A web server is the software that delivers web pages to your website's users.

The PHP software works in conjunction with the web server to allow the functionality necessary to deliver the interactive and dynamic web pages.

When a website user goes to a web page with a .php extension, for example by typing the URL into the web browser or by clicking a link, the request is sent to a web server.

That request is then sent to the PHP interpreter.

The PHP interpreter also communicates with file systems, databases and email servers as needed, and then delivers the request to the web server to return to the web browser.

In comparison, when a website user goes to a purely HTML generated web page; the server sends HTML data to the web browser without having the code interpreter.

Simple Example of PHP Program

PHP can be placed directly inside HTML.

Example

<html>

<head>
 

<title>WAGmob Applications</title>

</head>

<body>

<?php

echo "Simple n Easy App World!";

?>
 

</body>

</html>

The inclusion of PHP within HTML files is called escaping in the PHP documentation.

There are different methods for escaping :

Example

1. <? echo("<h1>Hello</h>"); ?>

2. <?php echo("<h1>Hello</h>"); ?>

3. <script language="php">

          echo ("<h1>Hello</h>");

         </script>

4. <% echo("<h1>Hello</h>"); %>

The second method is easy to read.

What Can PHP Do?

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.

CGI (Common Gateway Interface), is a specification for transferring information between a World Wide Web server and a CGI program.

A CGI program is any program designed to accept and return data that conforms to the CGI specification.

The program could be written in any programming language, including C, Perl, php, Java, or Visual Basic.

There are three main areas where PHP scripts are used:

Server-side scripting

This is the most traditional and main target field for PHP.

You need three things to make this work. The PHP parser (CGI or server module), a web server and a web browser.

You need to run the web server, with a connected PHP installation. You can access the PHP program output with a web browser, viewing the PHP page through the server.

All these can run on your home machine if you are just experimenting with PHP programming.

Command line scripting

You can make a PHP script to run without any server or browser.

You only need the PHP parser to use it this way.

This type of usage is ideal for scripts regularly executed using cron (on UNIX or Linux) or Task Scheduler (on Windows).

These scripts can also be used for simple text processing tasks.

Writing desktop applications

PHP is probably not the very best language to create a desktop application with a graphical user interface.

But if you would like to use some advanced PHP features in your client-side applications you can also use PHP-GTK to write such programs.

Advantages of PHP

Simple and very easy to learn.

Support for both structural programming and object oriented programming.

PHP has support services using protocols such as LDAP, IMAP, SNMP, NNTP, POP3, HTTP, COM (on Windows) and countless others.

Easy deployment and cost effective hosting.

Disadvantages of PHP

Security flaws depending on free libraries that you work with.

Not good to create desktop applications.


Translate

CR Zaman. Powered by Blogger.

Recent Posts

Popular Posts