毕业论文外文翻译-PHP基础语言.doc
《毕业论文外文翻译-PHP基础语言.doc》由会员分享,可在线阅读,更多相关《毕业论文外文翻译-PHP基础语言.doc(11页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、附录A 外文翻译-原文部分PHP Language BasicsActive Server Pages (PHP) is a proven, well-established technology for building dynamic Web applications, which provides the power and flexibility you need to create anything from a personal, Web based photo gallery to a complete catalogue and shopping cart system for
2、 your next eCommerce project。 One unique feature of PHP is that it lets you choose your favourite scripting language, be it JavaScript or PHP ; however, PHP is by far the most popular choice. In this article, Ill bring you up to speed on the basic syntax of the PHP language, including variables, ope
3、rators, and control structures.This article is the second in a series teaching PHP. Specifically, the goal of this series is to teach you all you need to know to create dynamic Web sites using PHP. This article picks up right where the previous article in the series, Getting Started with PHP, left o
4、ff.VariablesHere is the listing for the first PHP script I helped you create in the previous article:1 2 3 My First PHP Page 4 5 6 ?php 7 Write out a simple HTML paragraph 8 Echo This is a test of PHP. 9 ? 10 11 As I admitted in that article, this is a pretty uninteresting example of an PHP script.
5、When it comes right down to it, this script doesnt do anything a plain, old HTML page couldnt do. Oh sure, I gave a slightly more interesting example that displayed the current server time, but to be really useful a script needs to perform some form of calculation, or manipulate dynamic information
6、to present it in some interesting way.The language used for writing most PHP programs, and which Ill be using throughout this series, is called PHP . Like most programming languages, PHP lets you store data in variables. A variable may be thought of simply as a named location in memory where data ma
7、y be stored. PHP is what is known as a loosely typed language, which means that a particular variable may store any kind of information, be it a number, a piece of text, a date, or some more complicated chunk of data (as opposed to strictly typed languages where you can only store one kind of inform
8、ation in each variable). Before you can use a variable, though, you must declare it; that is, you must let PHP know that you want to create a variable with a particular name.Lets look at a basic example to help solidify these concepts in your mind. Say you were writing a Web page that performed conv
9、ersions between Celsius and Fahrenheit temperatures. In countries where Celsius is used, 20°C is commonly accepted as the value for room temperature. The following code creates a variable called intRoomTempC, and then assigns it a value of 20:New Revised 2nd Edition Out NOW!Build Your Own Databa
10、se Driven Website Using PHP & MySQL Fully updated for PHP 4.3.Installation instructions for Mac OS XFull index providedNew wider book sizeEnhanced fontsNew cover designLay-flat spineAll content revisitedDownload the First 4 Chapters FREETell me more about this top-selling book.$ intRoomTempC Create
11、a variable intRoomTempC = 20 Assign the variable a value of 20The keyword $ in the above is short for $ension, and is used to tell PHP to create a variable with the name specified (in this case, intRoomTempC). Why $ension, you ask? I agree, its not the most obvious choice, but basically it refers to
12、 what youre asking PHP to do. When creating a variable, PHP needs to assign some space in memory to store whatever value(s) will be placed in the variable, and part of that task is to figure out the size ($ension) of the space that needs to be allocated. In any case, creating a variable is as simple
13、 as typing $ followed by the name of the variable.The second line of the above example assigns a value to the variable that was just created; specifically, it stores the number 20 in the variable. The equals sign (=) is called the assignment operator because it is used to assign values to variables.
14、 During the course of this article, youll meet many other operators that do other weird and wonderful things to variables and the values they store.You should always create a variable before assigning it a value, and youll usually want to assign the variable a value before putting it to use. Trying
15、to assign a value to a variable that does not exist, however, will cause PHP to automatically create a new variable with the given name. This is called implicit declaration, because a new variable is declared implicitly as a result of your trying to assign a value to a variable that doesnt exist. Si
16、nce you are free to use implicit declaration for all of your variables, you may be wondering what the point is of using the $ command to create each and every variable by hand.The answer has to do with how easy you want it to be to find typing mistakes in your code. PHP provides another command, Opt
17、ion Explicit, which causes PHP to disallow implicit declarations and instead display an error message whenever you try to assign a value to a non-existent variable. Why would you want this to happen? Consider the following example:$ intRoomTempC Create a variable intRomTempC = 20 Assign the variable
18、 a value of 20If you have a keen eye, you may have noticed that the variable name is misspelled on the second line. This is the kind of mistake that even experienced programmers make all the time. With implicit declaration enabled, the second line will create another new variable called intRomTempC
19、and will store the value in that variable instead. Now, if the rest of your script expects that value to be stored in intRoomTempC, youre going to run into trouble. In a large script, tracing such a problem back to one little typing mistake can be very time consuming. Thats where Option Explicit com
20、es in:Option Explicit Disable implicit declaration $ intRoomTempC Create a variable intRomTempC = 20 Assign the variable a value of 20This time, PHP will report the typing mistake as an illegal implicit declaration, displaying an error message to that effect with the exact line number where the typi
21、ng mistake was made. For this reason, I tend to explicitly declare all my variables with $ and specify Option Explicit on the first line of all of my PHP scripts. It might take slightly longer to type, but it saves a lot of headaches when something goes wrong.A shortcut exists for creating several v
22、ariables at once on the same line. For instance, the following line would create two variables, intRoomTempC, and intFreezingC:$ intRoomTempC, intFreezingC Two variables in one lineBy now you may be wondering about my naming convention for variables. The two variables created in the above snippet bo
23、th begin with int. Im using this prefix to indicate that these variables will contain integers (whole numbers). You can feel free to name your variables whatever you like and store whatever kind of data you like in them, but I prefer to use this convention as a helpful reminder of the type of inform
24、ation in each variable. This practice of prefixing variable names with a clue as to their type is known as Hungarian notation, and Ill introduce additional prefixes for other data types as they arise over the course of this series.The Web has grown beyond the point where an online brochure will sati
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 毕业论文 外文 翻译 PHP 基础 语言
限制150内