Linux 版 (精华区)
发信人: netiscpu (网中鸟~~flying), 信区: Linux
标 题: [中英]PHP/MySQL教程(2-4)第一个PHP脚本
发信站: 紫 丁 香 (Thu Jan 13 04:07:40 2000), 转信
[中英]PHP/MySQL教程(2-4)第一个PHP脚本
[原作者] Graeme Merrall
[出处] http://hotwired.lycos.com/webmonkey/programming/php/tutorials/tutorial4.html
[译者] netiscpu
PHP/MySQL Tutorial
by Graeme Merrall
======================================================================
第一个PHP脚本
Your First Script
当你发现自己马上就可以使用MySQL/PHP时,一定会感到非常兴奋,确实软件的安装过
程就像一个黑洞,因为从这个系统到那个系统之前,往往有很多差别.不过现在,你的
数据库可以启动运行,PHP也编译完成,并且和我们的Web服务器安装在一起,还能够识
别".php3"文档了,应该感到无比幸运!
You'll be glad to know that the really tricky stuff is behind you.
Installation of software is always a black hole because so much
changes from system to system. But with any luck your database is up
and running,and PHP is compiled and installed with our Web server and
able to recognize documents with .php3 extensions.
让我们马上投入PHP/MySQL的世界,开始写下第一个PHP脚本.创建一个文本文件,包含
以下内容:
<html>
<body>
<?php
$myvar = "Hello World";
echo $myvar;
?>
</body>
</html>
Let's dive right in and write our first script. Create a text file
containing the following:
<html>
<body>
<?php
$myvar = "Hello World";
echo $myvar;
?>
</body>
</html>
然后调用该URL,比如,http://myserver/test.php3,这是你应该看到一个显示"Hello
World"的页面.如果你得到的是一个错误信息,检查PHP 文档,看看是否所有的东西都
安装正确了.
Now call up the URL, for instance, http://myserver/test.php3. You
should see a page containing the text "Hello World." If you get an
error message, check the PHP documentation to see if you set things
up properly.
就是它了!这就是你的第一个PHP脚本,如果你查看该页面的HTML源代码,你会看到那
里只有文字"Hello World".
That's it! That's your first PHP script. If you view the HTML source
for the page, you'll see that there is only the text. Hello World
这是因为PHP引擎已经检查了该页,处理了所有的代码区,并且仅仅返回HTML代码.
That's because the PHP engine has examined the page, processed any
code blocks that it found, and returned only HTML.
首先,你会注意到以上脚本的分割符,即以"<?php"开始.这表明PHP代码区开始,最后
"?>"代表代码区结束.PHP的威力在于这些代码可以放置在你的HTML代码的任何地方,
任何次数.稍后,我们还要讨论如何配置PHP,以便于使用更短的标记:"<?"和"?>",但
是这将导致与XML不兼容,所以使用时要特别注意.如果你正从ASP转换过来,甚至可以
将PHP配制成使用"<%"和"%>"作为代码区分割符.
The first thing you'll notice about the script above are the
delimiters. These are the lines that start <?php. This indicates the
start of a block of PHP code, and ?> indicates the end of the block.
The power of PHP is that these can be placed anywhere - and I mean
anywhere - in your code in any number of ways. Later we'll see some
interesting uses for these, but for now let's keep it simple. If you
wish, you can also configure PHP to use short tags, <?, and ?>, but
these are not XML compliant, so be careful. If you're making the
switch from ASP, you can even configure PHP to use the <% and %>
delimiters.
另一件事你会注意到的是每一行都以";"作为结束符,这些广为人知的分割符用于将
一组指令从其它指令中区分出来,这也可以灵活的用于将整个PHP脚本写在一行上,
然后用分号区分各个部分,但是这样会使代码显得杂乱无章,所以我们在每个分号之
后另起一行,务必记住每一行要以一个分号结束.
Another thing you'll notice is the semicolon on the end of each line.
These are known as separators and serve to distinguish one set of
instructions from another. It is feasible to write an entire PHP
script on one line and separate the portions with semicolons. But that
would be a mess, so we'll add a new line after each semicolon. Just
remember that each line must end in a semicolon.
最后,你还会看到单词"myvar"前面有一个"$"符号,这个符号告诉PHP它是一个变量,
我们将字符串"Hello World"赋值给变量$myvar,一个变量可以包含多个数组.但是
无论如何,所有的变量都是以"$"符作为开始标识.
Finally, you see that the word myvar begins with a dollar sign. This
symbol tells PHP that this is a variable.We assigned the words "Hello
World" to the variable $myvar. A variable can also contain numbers
or an array. Either way, all variables start with the dollar sign
symbol.
PHP的真正威力来源于它的函数,其中有基本的处理指令,如果你将所有的可选函数都
添加到PHP中,函数数量将达到700个以上,所以,使用这些函数,你可以做很多事情.
The real power of PHP comes from its functions. These are basically
processing instructions. If you add up all of the optional add-ins
to PHP, there are more than 700 functions available. So there's quite
a bit you can do.
现在让我们看看如何通过PHP操作MySQL.
Now let's add some MySQL to the picture.
[未完待续]
--
Enjoy Linux!
-----It's FREE!-----
※ 来源:.紫 丁 香 bbs.hit.edu.cn.[FROM: uststf1-nc2.ust.]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:4.359毫秒