毕业论文外文翻译-PHP基础语言.doc

上传人:豆**** 文档编号:29954930 上传时间:2022-08-02 格式:DOC 页数:11 大小:69KB
返回 下载 相关 举报
毕业论文外文翻译-PHP基础语言.doc_第1页
第1页 / 共11页
毕业论文外文翻译-PHP基础语言.doc_第2页
第2页 / 共11页
点击查看更多>>
资源描述

《毕业论文外文翻译-PHP基础语言.doc》由会员分享,可在线阅读,更多相关《毕业论文外文翻译-PHP基础语言.doc(11页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

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

25、sfy a typical companys needs for its Web presence. If you aim to market yourself as a Webmaster these days, you need to have some skill building online applications Web sites that users can interact with, whether to get something done (e.g. send email), get information targeted to their specific nee

26、ds (e.g. a real-time stock quote), or to interact with other users (e.g. an online community).In this series of articles, Ill guide you through the process of learning one of the most popular frameworks for creating dynamic Web sites such as these Active Server Pages (PHP). If you can secure a stron

27、g knowledge of PHP, as well as some practical experience building Web sites with it, you should never have trouble getting work as a Web developer. A quick search of your favourite online job directory with the keyword PHP should be more than enough to convince you of that.In this first article, Ill

28、 help you get your feet wet by introducing the PHP programming language, and how to use it to write dynamic Web pages with PHP. Before I get to that, I shall stop to explain how server-side scripting, and PHP in particular, differs from other Web scripting technologies that you may be familiar with,

29、 such as client-side JavaScript. This will get you armed with the proper vocabulary and ensure that were on the same page before launching headlong into the brave, new world of PHP.Server-Side ScriptingTo understand where PHP fits into the big picture of Web development, you need to understand the c

30、oncept of a server-side scripting language. If youve programmed Web pages in Perl, PHP, JSP, or Cold Fusion before, you can safely skip this section all of those are server-side scripting languages, and PHP works in much the same way. If youre coming to PHP armed only with knowledge of HTML (and per

31、haps with some CSS and/or JavaScript experience) then youll find that server-side scripting is quite a bit different.Let me begin by giving you a quick review of how standard, non-PHP Web pages work. As shown in Figure 1, the Web browser on the client computer (the computer belonging to the user) ma

32、kes a request for a page, say file.html (1). Assuming the requested file exists on the Web host computer where the Web Server software can find it, that software replies to the request by sending the file back to the browser (2). Any additional files (images, for example) required to display the pag

33、e are requested and received in the same way. The protocol used for this exchange, and indeed for all communication between Web browsers and Web servers is called Hypertext Transfer Protocol (HTTP).If youve ever used any JavaScript in your pages, you know that the requested Web page (file.html) can

34、contain, in addition to plain HTML code, small programs written in JavaScript. These programs, or scripts, are read and executed by the Web browser while the page is displayed in the browser. So the Web browser must understand not only how to read HTML and display textand images, but it must also be

35、 able to run JavaScript programs appearing inside Web pages. This arrangement, where the Web browser runs the script after receiving it from the Web server, is called client-side scripting. The name makes sense all of the script runs on the client-side the right-hand side of Figure 1. The Web server

36、 is completely oblivious to whether the file it is sending contains a script or not; its all up to the browser (the client) to handle execution of the script.PHP fits into a different category of technologies, called server-side scripting, where it is no longer the browser running on the client that

37、 is responsible for running the script; instead, it is the Web server that runs the script. This process is illustrated in Figure 2. As before, the Web browser requests a file (1). In this case, however, the filename ends with .php (file.php, for example), branding it as a file containing an PHP scr

38、ipt that needs to be processed by the server. The server recognizes this, and instead of directly sending the requested file back to the browser, it sends the file to the PHP scripting engine (2). The engine is a component of the Web server software that can interpret PHP scripts and output the resu

39、lts as HTML. The trick here is that any given script can output different HTML each time it is run, so what comes out of the PHP engine can be different for each client (browser) request. That dynamically generated page is then sent to the browser in response to its request (3), in exactly the same

40、way as the static page was sent in the previous example.Just as when the page contained client-side JavaScript and the server was completely unaware of this fact, when the page contains server-side PHP script, the browser does not know this at all. The PHP code contained in the page is interpreted a

41、nd converted to plain HTML by the PHP engine before the browser gets to see it; so as far as the browser is concerned an PHP page looks just like any normal Web page. All the work is done on the server-side; thus the name, server-side scripting.附录B 外文翻译-译文部分PHP基础语言PHP是构建动态网页应用的被实践证明了的技术,为你需要创建任何的东西从

42、一个基于图片库个人网页到一个完整的目录,为你的下一个商业项目提供全面的系统提供了强大的功能和灵活性。PHP唯一的特性即让你选择你最喜欢的脚本语言,像JavaScript 或者PHP ,然而PHP 是至今为止最流行的脚本语言。在本文中,我将带你学习PHP 的基本syntax,包括变量,操作数和控制结构。本文是PHP系列教程的第二本,该系列教程的目标是教你一切你需要了解使用PHP创建动态网页。本文需要在掌握在系列教程的前面部分,从PHP学起,不要遗漏。变量 这里列出了在前面部分我帮你创建的PHP脚本的开头:1 2 3 My First PHP Page 4 5 6 ?php 7 Write out

43、 a simple HTML paragraph 8 Echo This is a test of PHP. 9 ? 10 11 当然我承认在文章中,这是一个PHP脚本完整而没有兴趣的例子。当写下例子,这个脚本不能做普通传统网页不可能做的任何事情。当然,我给了一个稍微有兴趣的例子,它显示当前服务器的时间,但是真正有用的脚本使用有兴趣的方式需要执行一些计算的格式,操纵目前动态信息。 写PHP程序使用最多的语言,我们通过这个系列叫做PHP 。像许多其它程序语言一样, PHP 让你用变量存储数据。一变量可以被认为是内存里的一个位置,这个位置是用来存储数据的。PHP 被认为是最自由的一类程序语言,这意

44、味着一特殊的变量可以存储任何类型的信息,可以是一个数字,一篇文章,一个数据或者一些复杂的数据堆(与严格程序语言相对的,你只能用每一个变量来存储一种类型的信息)。在你使用一个变量时,虽然你必须声明它,即你必须让PHP了解你想用一个特殊的名字创建一个变量。 让我们看一个例子来巩固在你脑子里的概念。即你在做一张网页是执行Celsius 和Fahrenheit温度的转换。Celsius在乡村被使用,20°。C被认为是一个房间温度的值。下面的代码是创建一个intRoomTempC的变量,然后赋值为20: New Revised 2nd Edition Out NOW!Build Your Own

45、Database 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

46、Create a variable intRoomTempC = 20 Assign the variable a value of 20在上面关键字$的范围比较小,在使用PHP 创建一个名字确定的变量(就如intRoomTempC)你会问为什么要范围呢?我同意,这不是最清晰的选择,但是基本上涉及了 你问PHP 所做的一切。当创建一个变量,PHP 需要在内存中留一些空间来存储放在变量中的任何值,它的部分任务是明确所分配的空间大小。在任何情况下,创建一个变量就像打$ 后跟变量名。 上面例子的第二行赋了一个值给刚创建的变量,明确了它变量赋值是数字20。等号是一个明确的操作符,因为它来确定变量的赋值

47、。在本文的课程学习中,你将碰到许多其他的操作符,用来给变量另外离奇而有意思的东西,以及它们存储的值。你应该在确定一个值时,先创建一个变量,通常在使用它前给想给它一个确定的值。试着给变量一个不存在的值,不管怎么样,将引起自动创建一个全名的新变量。这个叫隐式说明,因为新的变量被隐式的说明由于你试者给一个不存在的变量赋值。由于你能自由的对你所有的变量进行隐式说明,你可以知道的关键是手动的用$命令创建任何一个和每一个变量。 如何容易处理的找出在你的代码中的打字中错误的解答。PHP 提供了另一个命令Option Explicit ,在你试着给一个不存在的变量赋值时,它将导致不允许的隐式说明和代替显示错误

48、信息。你想为什么会发生这种情况呢 ?考虑一下下面的例子: $ intRoomTempC Create a variable intRomTempC = 20 Assign the variable a value of 20如果你有一双敏锐的眼睛,你可可以注意到第二行的变量名拼写错误。这种类型的错误甚至在有经验的程序员中也一直存在。在变量能隐式说明的帮助下,第二行将创建另一个新的变量intRomTempC,然后代替那个变量存储值。现在,你的剩余的脚本希望在intRoomTempC存储值,你的运行将出现问题。在更大的脚本中,对像这样一个小的打字中错误的追踪是非常的费时间的。Option Explicit的来源:这时,PHP将用非法的隐式说明报告打印错误,用精确的每一行数字显示打字中错误信息。因为这个原因,我往往用$来隐式说明所有的我的变量以及明确我的PHP脚本中第一行

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 小学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁