Custom Search

Sunday, June 20, 2010

Flow Control and Iteration

Flow Control and Iteration
Flow control and iteration are two very useful features of most programming languages. Without them all programs would have to be linear and if you wanted something to happen three times, you would have to code it three times.
Flow control means exactly what it sounds like it should, controlling the flow of something. When using flow control for programming, what you are doing is regulating the order in which the code is executed, how many times it is executed, and if it is executed at all Programmatic flow control can be broken into three primary categories.

Conditionals
Conditionals allow us to specify wether or not to run a selected piece of code based on some prior condition. It is the first topic we will cover. It is broken into two lectures, the first is an introduction to conditionals. The second is a discussion of some of the more advanced tools available in PHP for comparing things.Iteration
Our next topic is iteration. Iteration, also known as looping, us to specify that a piece of code be run multiple times. Depending on circumstances, that can be one or more or zero or more times.
Functions Our last primary flow control tool is functions. Functions allow us to create named blocks of code to be called by name elsewhere in the script. This allows us to run a piece of code multiple times from multiple places in the script. It is also the first step to writing good, modular code. This section contains both a brief introduction to functions and a more detailed look at advanced function topics in PHP

what is use php

  • php is a scripting language that is often embedded into html to add functions html alone can't do. php allows you to collect, process and utilize data to create a desired output. in short, it let's you interact with your pages.
    php is able to preform a number of tasks including printing data, making numeric calculations and making simple boolean choices. from this you can create more complex loops and functions to make your page generate more specialized data,

Database Access
One of set modules control database access. Using PHP with MySQL has become common enough that the MySQL interface is now part of core PHP instead of a plug-in module. Most other databases have modules that can be included in a PHP build to allow access. PHP can access most any SQL or ODBC database. It can both read and write information in the database.

This opens up the door for a whole variety of online business applications that require data storage on the server. Because of this, PHP is becoming an increasingly popular tool for e-commerce.

File Access

PHP can read and write files. It can also do basic file and directory maintenance. Because of this, you can use it to do such things as edit documents remotely. It can also be used to search flat file collections for the existence of a given file or for the existence of information stored in files and return the results. Information does not need to be coded into a database just to be accessible.

It can also take content and use it to generate files in various formats, including HTML and PDF. It is an incrasingly popular tool for processing XML for HTTP distribution. It can also take data and use it to generate e-mail, which is can send out through most any standard mail protocol.

Its ability to work across multiple data sources and return multiple content types makes it an ideal tool for things like search engines and message boards.

Application Control

PHP started as an application control language. Specifically, it was designed to handle access logging for HTTP servers. This ability has expanded greatly and now PHP can even be used as a scripting language in such applications as Microsoft Word and Excel.

Graphics
PHP can not only manage text content, it can also manage graphic content. It can be used to create graphs and charts. It can be used to generate GIF and PNG images on the fly, allowing you, for instance, to have a button template that has the text added to it dynamically before being sent to the client. This means you don't need a new image for each button, just one image that has the text added as needed for each individual button.

Extensible
PHP is extensible. It is written in C and the underlying source can be expanded on with new modules written in the same. It is also open source, so engaging in such expansion is permitted and encouraged

What Can PHP Do?

PHP is a server-side scripting language whose primary purpose is to generate HTML content. Its creator, Rasmus Lerdorf defines it as "a cross-platform, HTML-embedded, server-side web scripting languageWith the current direction of the Web, it is easily being adapted to writing out all forms of XML content as well. The most recent version of PHP

It was originally developed as a set of server-side modules to perform some specific Web-server tasks on small, Unix-based Web servers. Since then PHP has grown beyond the work of one man writing some tools for his own use and into one of the most popular server-side scripting languages in the Web.

Three thing make PHP popular. The first is that it is easy: easy to implement, easy to learn, and easy to use. The second is that it is free. The third is that it runs on almost any Web server on almost any platform currently available.

PHP is both a scripting language and a collection of tools for performing various server-side functions in an HTTP, or Web, server. Since it is written as a collection of C-modules, it can go beyond server-side scripting and can also be used to execute scripts from the command line and for developing client-side GUI applications that can operate on most any platform.
The core features of PHP are built around the ability to process strings and arrays, as well as to work as an object-oriented programming language. Beyond this most of PHP is a collection of modules that can be added in on the server as needed to perform a large variety of specific tasks. In other words, it is a highly customizable application, and you can keept it small by only installing as much as you need to perform required tasks

Tuesday, January 5, 2010

Introduction:

PHP is pretty amazing: A language strung together by unpaid assistant programmers that today has the enviable distinction of being in use on more than a third of the planet’s Web servers. Flexible, scalable, extensible, stable, open—PHP is all of these and more, which is why it’s one of the most popular programming toolkits in the world.
Ask me why I like PHP, though, and my explanation has nothing to do with any of the preceding buzzwords and everything to do with how friendly and nonthreatening the language is. There’s no tortuous syntax or obfuscated code in the average PHP script: instead, it’s clear, understandable, and easy to read, and this makes both programming and debugging with it a pleasure. This is no small achievement: a shorter learning curve makes it easier for novice programmers to quickly begin “doing something useful” with the language, and increases both user interest and adoption levels. This isn’t just good design: it’s smart marketing as well! As an open-source project, PHP is completely free, and supported by a worldwide community of volunteers. This open-source, community-driven approach has produced a platform that is significantly more robust and error-free than many commercial alternatives. So using PHP is also good economics for organizations: it allows them to save on licensing fees and expensive server hardware, while simultaneously producing higher-quality products in shorter time frames.


Key Skills & Concepts
● Know PHP’s history
● Learn PHP’s unique capabilities for Web application development
● See how the components of a PHP system interact
● Understand the basic grammar and structure of a PHP script
● Create and run a simple PHP program
● Embed PHP in an HTML page

● Understand PHP’s simple data types
● Become familiar with some of PHP’s built-in functions
● Perform arithmetic operations
● Compare and logically test variables
● Handle data submitted through a Web form


Basic Development Concepts:
When developing a PHP application for the Web, the typical approach is to embed PHP code into one or more standard HTML documents using special “tags,” or delimiters.

Components PHP Applications:
● A base operating system (OS) and server environment (usually Linux)
● A Web server (usually Apache on Linux or IIS on Windows) to intercept HTTP
requests and either serve them directly or pass them on to the PHP interpreter for
execution
● A PHP interpreter to parse and execute PHP code, and return the results to the
Web server
There’s also often a fourth optional but very useful component:
● A database engine (such as MySQL) that holds application data, accepts connections from the PHP layer, and modifies or retrieves data from the database
An important corollary of this approach is that the PHP code is executed on the server, and not on the client browser. This allows Web developers to write program code that is completely independent of, and thus impervious to, browser quirks—an important advantage over client-side scripting languages, such as JavaScript, which often require complex logic to account for browser-specific differences. Further, because the code is all executed on the server and only the output is sent to the client, it is impossible for users to see the source code of your PHP program—an important security advantage over languages like JavaScript

MIXING WITH HTML CODING:

When the PHP parser reads a script, it executes only the code found between PHP tags; everything outside these tags is ignored by the parser and returned “as is.” This makes it extremely easy to embed PHP code within an HTML document to create Web pages that have all the formatting bells and whistles of standard HTML but can additionally perform complex calculations or read and manipulate data from external sources

The values assigned to a PHP variable may be of different data types, ranging from simple string and numeric types to more complex arrays and objects. You’ve already seen two of these, strings and numbers, in action in previous examples. Here’s a full-fledged example, which introduces three more data types:

● Booleans are the simplest of all PHP data types. Like a switch that has only two states, on and off, it consists of a single value that may be set to either 1 (true) or 0 (false). In this listing, $validUser is a Boolean variable set to true.
● PHP also supports two numeric data types: integers and floating-point values. Floatingpoint values (also known as floats or doubles) are decimal or fractional numbers, while integers are round numbers. Both may be less than, greater than, or equal to zero. In this listing, $size holds an integer value, while $temp holds a floating-point value.
● For non-numeric data, PHP offers the string data type, which can hold letters, numbers, and special characters. String values must be enclosed in either single quotes or double quotes. In the previous listing, $cat is a string variable containing the value 'Siamese'.
● You may also encounter the NULL data type, which is a “special” data type first
introduced in PHP 4. NULLs are used to represent “empty” variables in PHP; a variable of type NULL is a variable without any data. In the preceding listing, $here is NULL.

What Does PHP Do?

PHP does anything you want, except sit on its head and spin. Actually, with a little
on-the-fly image manipulation and dynamic HTML, it could probably do that, too. According to the PHP manual, “The goal of the language is to allow Web
developers to write dynamically generated pages quickly.”
Here are some common uses of PHP, all of which are a part of what you’ll learn in
this book:
• Perform system functions: create, open, read from, write to, and close files on
your system; execute system commands; create directories; and modify
permissions.
• Gather data from forms: save the data to a file, send data via e-mail, and return
manipulated data to the user.
• Access databases and generate content on the fly, or create a Web interface for
adding, deleting, and modifying elements within your database.
• Set cookies and access cookie variables.
• Start sessions and use session variables and objects.
• Restrict access to sections of your Web site.
• Create images on the fly.
• Encrypt data.