PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

PHP 能做什么?> <入门指引
Last updated: Sun, 25 Nov 2007

view this page in

简介

Table of Contents

PHP 是什么?

PHP(“PHP: Hypertext Preprocessor”,超文本预处理器的字母缩写)是一种被广泛应用的开放源代码的多用途脚本语言,它可嵌入到 HTML中,尤其适合 web 开发。

以上是一个简单的回答,不过这是什么意思呢?请看如下例子:

Example#1 一个介绍性的范例

<html>
    <head>
        <title>Example</title>
    </head>
    <body>

        <?php
        
echo "Hi, I'm a PHP script!";
        
?>

    </body>
</html>

请注意这个范例和其它用 C 或 Perl 语言写的脚本之间的区别――与用大量的命令来编写程序以输出 HTML 不同的是,我们用 PHP 编写了一个 HTML 脚本,其中嵌入了一些代码来做一些事情(例如,在本例中输出了一些文本)。PHP 代码被包含在特殊的起始符和结束符中,使得可以进出“PHP 模式”。

和客户端的 JavaScript 不同的是,PHP 代码是运行在服务端的。如果在服务器上建立了如上例类似的代码,则在运行该脚本后,客户端就能接收到其结果,但他们无法得知其背后的代码是如何运作的。甚至可以将 web 服务器设置成让 PHP 来处理所有的 HTML 文件,这么一来,用户就无法得知服务端到底做了什么。

使用 PHP 的一大好处是它对于初学者来说极其简单,同时也给专业的程序员提供了各种高级的特性。当看到 PHP 长长的特性列表时,请不要害怕。可以很快的入门,只需几个小时就可以自己写一些简单的脚本。

尽管 PHP 的开发是以服务端脚本为目的,但事实上其功能远不局限与此。请继续读后面的章节,在“PHP 能做什么”一节中将获得更多的信息。如果对 web 编程感兴趣,也可以阅读简明教程



PHP 能做什么?> <入门指引
Last updated: Sun, 25 Nov 2007
 
add a note add a note User Contributed Notes
简介
nostamar $AT$ g mail
30-Jan-2008 08:06
here is a "server-php >> html >> browser" process illustration:
http://www.lastown.com/forum/viewtopic.php?t=533

it shows the basic steps; first php code is parsed at server into html; then sent to browser, that understands html tags and renders them to the display the webpage, there's also some quick overview about the process.. worths taking a look at
winks716
19-Aug-2007 10:48
before html runs to show a webpage, php code runs first on web server.

so, when there lines as follow:

<table>
<tr>
<td>
  <?php
   
echo "php runs first!";
 
?>
</td>
</tr>
</table>

the first step is to run php code, we get:

<table>
<tr>
<td>
php runs first
</td>
</tr>
</table>

then, code is sent to browser, and we see somthing~
george dot langley at shaw dot ca
19-Jul-2007 08:02
"the code is executed on the server"

This is an important concept for the first-time PHP programmer to understand, so that when you get into string formatting later on, you understand the difference between formatting the on-screen content (as parsed by your browser) and formatting the HTML code (as returned by the server).
For example "/n" starts a new line in the HTML code, and its results are only seen if you look at the "source HTML". It is NOT the same as <br>!

PHP 能做什么?> <入门指引
Last updated: Sun, 25 Nov 2007
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites