当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > PHP 语法
You cannot view the PHP source code by selecting "View source" in the browser - you will only see the output from the PHP file, which is plain HTML. This is because the scripts are executed on the server before the result is sent back to the browser.
你不能直接通过浏览器中的“查看源文件[View sourse]”来浏览PHP源代码 —— 你只能从浏览器获取PHP文件的“HTML数据流”格式的结果。这是因为服务器是事先将脚本执行完毕以后再以HTML数据流的形式传回浏览器的,所以你看到的只能是处理完毕以后的结果。
A PHP scripting block always starts with <?php and ends with ?>. A PHP scripting block can be placed anywhere in the document.
PHP脚本代码段(scripting block)以<?php 为开始并以 ?> 结束。一个PHP脚本代码段可以被放置在文件中的任意位置。
On servers with shorthand support enabled you can start a scripting block with <? and end with ?>.
在服务器上另一种相对简便的书写方法是:以 <? 为开始并以 ?> 结束。
However, for maximum compatibility, we recommend that you use the standard form (<?php) rather than the shorthand form.
然而,为了发挥它最大的兼容性,我们建议使用标准的书写方式(<?php)而不是上述那种简便的写法,具体如下:
<?php ?> |
A PHP file normally contains HTML tags, just like an HTML file, and some PHP scripting code.
一个PHP文件通常包含HTML标签,类似于HTML文件;当然,它还包含脚本代码。
Below, we have an example of a simple PHP script which sends the text "Hello World" to the browser:
通过下面的代码,我们可以向浏览器发送一段文本:“Hello World!”
<html> <?php </body> |
Each code line in PHP must end with a semicolon. The semicolon is a separator and is used to distinguish one set of instructions from another.
PHP中的每段代码行必须以分号 “;” 做为结束的标志;分号“;”是用来区别不同指令的分隔符。
There are two basic statements to output text with PHP: echo and print. In the example above we have used the echo statement to output the text "Hello World".
对于PHP而言,有两种方法可以输出文本结果:echo 和 print。上述例子中,我们使用的是“echo”指令。
In PHP, we use // to make a single-line comment or /* and */ to make a large comment block.
在PHP中,我们使用 “//” 来注释单行语句,使用“ /* */ ”来注释多行语句,具体如下:
<html> <?php //这是条注释 /* ?> </body> |