PHP简介

 

PHP简介

作者:Haohappy  来源:PHPEye开源社区 2007-03-02 最后更新:2008-01-15 22:01:07

收藏: Yahoo书签  新浪ViVi 365Key网摘 天极网摘 POCO网摘 和讯网摘 

 

本文节选于《Programming PHP》第二版(中译名《PHP程序设计》第二版,Haohappy等译,电子工业出版社出版)Programming PHP中文版(第2版)

PHP是一种为创建HTML内 容而设计的简单但是功能强大的语言。本章内容涵盖了PHP语言的基本背景,描述了PHP的本质和历史、运行的平台,以及如何下载、安装和配置PHP。本章 的结尾给出一系列PHP实例程序,说明了如何使用一些PHP常用技术,例如表单数据处理、和数据库的交互、创建图像等。

1.1  PHP能做什么?

What Does PHP Do? 

PHP主要运用在以下3个方面。

服务器端脚本

PHP最初被设计用于创建动态的Web内容,它依然是最适合和擅长于此的。要生成HTML,你需要PHP解释器和一个Web服务器来发送文档。PHP同时也能够生成XML文档、图像、Flash动画、PDF文件,并因此而流行。

命令行脚本

PHP可以通过命令行运行脚本,就像Perl、awk或Unix shell。可以使用命令行脚本来执行系统管理任务,例如备份和日志解析。

客户端GUI应用

使用PHP-GTK (http://gtk.php.net),你可以使用PHP编写成熟的、跨平台的GUI应用程序。

在本书中,我们关注第一个方面,即使用PHP开发动态Web内容。

PHP可以在所有主流的操作系 统上运行,从不同种类的Unix包括Linux、FreeBSD和Solaris到Windows和Mac OS X。PHP可以用在所有主流的Web服务器上,包括Apache、Microsoft IIS, 和Netscape/iPlanet等服务器。

PHP非常灵活。例如,输出不仅仅限制于HTML,也可以生成其他格式的文本文件文档。PHP内置支持生成PDF文件、GIF、JPG和PNG图像,以及Flash电影。

PHP最重要的特性之一是它对数据库的广泛支持。PHP支持所有主流数据库(包括MySQL, PostgreSQL, Oracle, Sybase, 和 ODBC兼容的数据库),甚至也支持一些不常见的数据库。使用PHP从数据库获取内容并创建动态Web页面是非常简单的。

最后,PHP提供了一个PHP代码库来执行通用和常用的工作,例如使用PHP扩展和应用程序库(PEAR)来完成数据库抽象、错误处理等等。PEAR是一个可重用PHP组件的框架和布置系统。你可以从http://pear.php.net获取更多信息。

1.2  PHP发展简史

A Brief History of PHP 

在1994年Rasmus Lerdorf第一个设计出了PHP,但是今天人们使用的PHP和最初的版本有很大的不同。要知道PHP如何变成今天这个样子,就必须知道PHP的发展历史。以下是Rasmus讲述的故事。

1.2.1  PHP的发展

The Evolution of PHP

以下是1995年6月我在Usener新闻组comp.infosystems.www.authoring.cgi上所发布的PHP 1.0公告:

From: rasmus@io.org (Rasmus Lerdorf)

Subject: Announce: Personal Home Page Tools (PHP Tools)

Date: 1995/06/08

Message-ID: <3r7pgp$aa1@ionews.io.org>#1/1

organization: none

newsgroups: comp.infosystems.www.authoring.cgi

Announcing the Personal Home Page Tools (PHP Tools) version 1.0.

These tools are a set of small tight cgi binaries written in C.

They perform a number of functions including:

. Logging accesses to your pages in your own private log files

. Real-time viewing of log information

. Providing a nice interface to this log information

. Displaying last access information right on your pages

. Full daily and total access counters

. Banning access to users based on their domain

. Password protecting pages based on users' domains

. Tracking accesses ** based on users' e-mail addresses **

. Tracking referring URL's - HTTP_REFERER support

. Performing server-side includes without needing server support for it

. Ability to not log accesses from certain domains (ie. your own)

. Easily create and display forms

. Ability to use form information in following documents

Here is what you don't need to use these tools:

. You do not need root access - install in your ~/public_html dir

. You do not need server-side includes enabled in your server

. You do not need access to Perl or Tcl or any other script interpreter

. You do not need access to the httpd log files

The only requirement for these tools to work is that you have

the ability to execute your own cgi programs.  Ask your system

administrator if you are not sure what this means.

The tools also allow you to implement a guestbook or any other

form that needs to write information and display it to users

later in about 2 minutes.

The tools are in the public domain distributed under the GNU

Public License.  Yes, that means they are free!

For a complete demonstration of these tools, point your browser

at: http://www.io.org/~rasmus

--

Rasmus Lerdorf

rasmus@io.org

http://www.io.org/~rasmus

需要注意的是,以上消息里出现的URL和E-mail地址早已不复存在了。这个声明的内容反映了当时人们所关心的东西,例如,需要密码保护的页面,易于创建的表单,和在子页面存取表单数据。这个声明也说明了PHP最初定位于一个框架,是一些有用的工具的集合。

这份声明仅谈到了伴随PHP的工具,但后来的目标是创建一个易于扩展PHP和增加更多工具的框架。这些插件的业务逻辑是使用C语言来写的,调用各种C语言的函数来从HTML中取出标签。创建一个脚本语言从来不是我的计划。

那么,后来发生了什么呢?

Rasmus Lerdorf开始着手于多伦多大学的一个大项目,它需要一个工具来从不同的地方取得数据,并且展现在一个漂亮的基于Web的管理界面上。当然,我确定PHP可以完美地完成这个任务,但是由于性能的原因,PHP 1的各种小工具最好能整合到一起并且完整地集成到Web服务器中。

起初,我做了一些粗糙的东西作为NCSA(国家超级计算应用中心)Web服务器的补丁,使服务器支持PHP的核心功能。这种方法的问题是,用户不得不用此特定的粗糙版本来

替换Web服务器软件。幸运的是,在此前后Apache开始增加功能,并且Apache API使得它更加容易增加功能到服务器(如PHP)。

大约在一年后,许多工作都已完成而且关注的焦点也发生了变化。下面是1996年4月我发布的PHP版本2(PHP/FI)的声明。

From: rasmus@madhaus.utcs.utoronto.ca (Rasmus Lerdorf)

Subject: ANNOUNCE: PHP/FI Server-side HTML-Embedded Scripting Language

Date: 1996/04/16

Newsgroups: comp.infosystems.www.authoring.cgi

PHP/FI is a server-side HTML embedded scripting language.  It has built-in

access logging and access restriction features and also support for

embedded SQL queries to mSQL and/or Postgres95 backend databases.

It is most likely the fastest and simplest tool available for creating

database-enabled web sites.

    

It will work with any UNIX-based web server on every UNIX flavour out

there.  The package is completely free of charge for all uses including

commercial.

    

Feature List:

    

. Access Logging

Log every hit to your pages in either a dbm or an mSQL database.

Having hit information in a database format makes later analysis easier.

. Access Restriction

Password protect your pages, or restrict access based on the refering URL

plus many other options.

. mSQL Support

Embed mSQL queries right in your HTML source files

. Postgres95 Support

Embed Postgres95 queries right in your HTML source files

. DBM Support

DB,DBM,NDBM and GDBM are all supported

. RFC-1867 File Upload Support

Create file upload forms

. Variables, Arrays, Associative Arrays

. User-Defined Functions with static variables + recursion

. Conditionals and While loops

Writing conditional dynamic web pages could not be easier than with

the PHP/FI conditionals and looping support

. Extended Regular Expressions

Powerful string manipulation support through full regexp support

. Raw HTTP Header Control

Lets you send customized HTTP headers to the browser for advanced

features such as cookies.

. Dynamic GIF Image Creation

Thomas Boutell's GD library is supported through an easy-to-use set of

tags.    

It can be downloaded from the File Archive at: <URL:http://www.vex.net/php>

    

--

Rasmus Lerdorf

rasmus@vex.net

这是术语“脚本语言 (scripting language)”第一次被使用。PHP 1 中的过分简单的标签置换(tag-replacement)功能被替换成一个可以处理更复杂的嵌入性标签语言的解析器。用今天的标准来看,标签语言并不是 特别的复杂,但它和PHP1相比当然是复杂的。

这种改变的主要原因是:很少有 PHP 1用户真正有兴趣使用基于C语言的框架来创建附加的组件。大多数用户更感兴趣的是可以在Web页面上直接嵌入逻辑来创建条件性的HTML、自定义标签和其 他特性。PHP 1的用户要求有能力增加跟踪点击的页脚或有条件地发送各种HTML块。这导致了if标签的创建。一旦使用了if,也就必须使用else。从那时开始,无论 你是否愿意,最后都要完成一个完整的脚本语言。

到1997年中,PHP第二版 有了相当大的发展,并且吸引了大量的用户,但是底层解析引擎的稳定性仍然有一些问题。这个项目仍然主要是靠一个人的努力,和一点点来自其他人的帮助。这 时,Tel Aviv公司的Zeev Suraski 和 Andi Gutmans 自愿重写了底层的解析引擎,并且我们赞成将它们作为PHP 第3版的基础。其他人也自愿为PHP的其他部分工作,PHP项目从一个人的项目转变成一个有很多开发者的真正的世界性开源项目。

下面是在1998年6月PHP3.0的声明。

June 6, 1998 -- The PHP Development Team announced the release of PHP 3.0,

the latest release of the server-side scripting solution already in use on

over 70,000 World Wide Web sites.

    

This all-new version of the popular scripting language includes support

for all major operating systems (Windows 95/NT, most versions of Unix,

and Macintosh) and web servers (including Apache, Netscape servers,

WebSite Pro, and Microsoft Internet Information Server).

    

PHP 3.0 also supports a wide range of databases, including Oracle, Sybase, Solid,

MySQ, mSQL, and PostgreSQL, as well as ODBC data sources.

    

New features include persistent database connections, support for the

SNMP and IMAP protocols, and a revamped C API for extending the language

with new features.

    

"PHP is a very programmer-friendly scripting language suitable for

people with little or no programming experience as well as the

seasoned web developer who needs to get things done quickly.  The

best thing about PHP is that you get results quickly," said

Rasmus Lerdorf, one of the developers of the language.

"Version 3 provides a much more powerful, reliable and efficient

implementation of the language, while maintaining the ease of use and

rapid development that were the key to PHP's success in the past,"

added Andi Gutmans, one of the implementors of the new language core.

    

"At Circle Net we have found PHP to be the most robust platform for

rapid web-based application development available today," said Troy

Cobb, Chief Technology Officer at Circle Net, Inc.  "Our use of PHP

has cut our development time in half, and more than doubled our client

satisfaction.  PHP has enabled us to provide database-driven dynamic

solutions which perform at phenomenal speeds."

    

PHP 3.0 is available for free download in source form and binaries for

several platforms at http://www.php.net/.

    

The PHP Development Team is an international group of programmers who

lead the open development of PHP and related projects.

    

For more information, the PHP Development Team can be contacted at

core@php.net.

在PHP 3.0发布之后,用户数量真正开始激增。PHP 4.0由大量对改变PHP基本架构感兴趣的开发者促生。这些改变包括在语言和Web服务器之间的抽象层,增加了一个安全线程机制,增加了一个更加高级的、 双平台的分析/执行 标签分析系统。新的解析器,由Zeev 和Andi主要编写, 被命名为Zend引擎。在很多开发人员做了大量工作之后,PHP 4.0于2000年5月22日发布。

从这个版本发布开始,只有很少 的PHP 4.0的小发布版本,最新版本是4.3.11。而在本书付印后,PHP 5.0版本也将已经发布。现在已经有了一些小版本译注1发布,这些版本的稳定性也相当高。当你看到此书时,在新版本的PHP中已经有了一些重要的进步,如 XML、面向对象和SQLite这些主要的改进。同时也有很多其他的小改进,如函数增加和特性的增强等等。

1.2.2  PHP的成长

The Growth of PHP

图1-1通过Netcraft (http://www.netcraft.com)自2000 1月收集的PHP使用数量来说明PHP的成长情况。这个图展示了唯一IP地址下启用PHP模块的Apache服务器的总数(含19720597个域名, 1310181个IP地址)。2001年的那个低谷反映了当时互联网的“冬天”导致的很多.com公司的倒闭和消失的情况,当时Netcraft找到的服 务器的数量也明显减少。你可以在以下地址看到这个统计图的最新版本:http://www.php.net/usage.php

                           

图1-1:2000年以来PHP应用的增长情况

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值