The I mpor tance of the I nstr uction Ter minator.The instruction terminator, also known as the semicolon (;), is absolutely required at the end of commands. The instruction terminator tells the PHP parser, "I'm done with this command, try the next one."
If you do not end commands with a semicolon, the PHP parser will become confused, and your code will display errors. These next steps show you how these errors come about and, more importantly, how to fix them.
1. Open a new file in your text editor.
2. Type the following HTML:
<HTML>
<HEAD>
<TITLE>Making an Error</TITLE>
</HEAD>
<BODY>
3. Type the following PHP code:
<?
echo "<P>I am trying to produce an error</P>"
echo "<P>Was I successful?</P>";
?>
4. Add some more HTML so that the document is valid:
</BODY>
</HTML>
5. Save the file with the name errorscript.php.
6. Place this file in the document root of your web server.
7. Open your web browser and type http://127.0.0.1/er r or scr ipt.php.
What a nasty error! The error message says that the error is on line 8. Take a look at lines 7 and 8 of the script:
echo "<P>I am trying to
produce an error</P>"
echo "<P>Was I
successful?</P>";
Line 7 does not have an instruction terminator, and line 8 starts a new command. The PHP parser doesn't like this, and it tells you so by producing the parse error.
This error is easy enough to fix:
1. Open the errorscript.php file.
2. On line 7, add the instruction terminator (;) to the end of the line:
echo "<P>I am trying to produce an error</P>";
3. Save the file.
4. Place this file in the document root of your web server.
5. Open your web browser and type http://127.0.0.1//er r or scr ipt.php.
After you fix line 7, the PHP parser can deal with the file, and the rest of the output is successful. Avoid this and other errors by paying close attention to things such as semicolons and, as you'll learn in the next section, quotation marks!
Julie C. Melni,《PHP 5 Fast & Easy Web Development》,Course Technology ,2004,P40-P50
PHP和HTML混合
PHP解析器识别一些类型的PHP开始和结束标签。它将尝试执行任何这些标记之间,所以它最好是有效的代码!
学习研究表4.1中被PHP解析器的三个主要的开始和结束标记。
接下来,您将使用所有三套标签在脚本中,我承诺将执行没有错误。
1.在你的文本编辑器,打开一个新文件。
2. 输入以下代码,使用第一个标记类型:
<?php
echo "<P>This is a test using the first tag type.</P>";
?>
Type the following code, which uses the second tag type:
<?
echo "<P>This is a test using the second tag type.</P>";
?>
4.输入以下代码,使用第三个标签类型:
<script language="php">
echo "<P>This is a test using the third tag type.</P>";
</script>
5. 保存文件的名称为phptags.php。
6.在网页服务器根目录文件夹中建立这个文档。
7.打开浏览器并输 http://127.0.0.1/phptags.php。
在您的web浏览器中,您应该看到脚本的结果。
在下一节中,您将了解,将PHP块内部HTML并不是一件可怕的事情。
Mixing PHP and HTML
代码融合
- 上一篇:注射成型模具残余应力英文文献和中文翻译
- 下一篇:JSP的优点英文文献和中文翻译
-
-
-
-
-
-
-
中国传统元素在游戏角色...
浅析中国古代宗法制度
上市公司股权结构对经营绩效的影响研究
现代简约美式风格在室内家装中的运用
g-C3N4光催化剂的制备和光催化性能研究
C++最短路径算法研究和程序设计
巴金《激流三部曲》高觉新的悲剧命运
高警觉工作人群的元情绪...
NFC协议物理层的软件实现+文献综述
江苏省某高中学生体质现状的调查研究