php外文翻译

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

附录A外文翻译-原文部分PHPLanguageBasicsActiveServerPages(PHP)isaproven,well-establishedtechnologyforbuildingdynamicWebapplications,whichprovidesthepowerandflexibilityyouneedtocreateanythingfromapersonal,WebbasedphotogallerytoacompletecatalogueandshoppingcartsystemforyournexteCommerceproject。OneuniquefeatureofPHPisthatitletsyouchooseyourfavouritescriptinglanguage,beitJavaScriptorPHP;however,PHPisbyfarthemostpopularchoice.Inthisarticle,I'llbringyouuptospeedonthebasicsyntaxofthePHPlanguage,includingvariables,operators,andcontrolstructures.ThisarticleisthesecondinaseriesteachingPHP.Specifically,thegoalofthisseriesistoteachyouallyouneedtoknowtocreatedynamicWebsitesusingPHP.Thisarticlepicksuprightwherethepreviousarticleintheseries,GettingStartedwithPHP,leftoff.VariablesHereisthelistingforthefirstPHPscriptIhelpedyoucreateinthepreviousarticle:1html2head3titleMyFirstPHPPage/title4/head5body6?php7'WriteoutasimpleHTMLparagraph8EchopThisisatestofPHP./p9?10/body11/htmlAsIadmittedinthatarticle,thisisaprettyuninterestingexampleofanPHPscript.Whenitcomesrightdowntoit,thisscriptdoesn'tdoanythingaplain,oldHTMLpagecouldn'tdo.Ohsure,Igaveaslightlymoreinterestingexamplethatdisplayedthecurrentservertime,buttobereallyusefulascriptneedstoperformsomeformofcalculation,ormanipulatedynamicinformationtopresentitinsomeinterestingway.ThelanguageusedforwritingmostPHPprograms,andwhichI'llbeusingthroughoutthisseries,iscalledPHP.Likemostprogramminglanguages,PHPletsyoustoredatainvariables.Avariablemaybethoughtofsimplyasanamedlocationinmemorywheredatamaybestored.PHPiswhatisknownasalooselytypedlanguage,whichmeansthataparticularvariablemaystoreanykindofinformation,beitanumber,apieceoftext,adate,orsomemorecomplicatedchunkofdata(asopposedtostrictlytypedlanguageswhereyoucanonlystoreonekindofinformationineachvariable).Beforeyoucanuseavariable,though,youmustdeclareit;thatis,youmustletPHPknowthatyouwanttocreateavariablewithaparticularname.Let'slookatabasicexampletohelpsolidifytheseconceptsinyourmind.SayyouwerewritingaWebpagethatperformedconversionsbetweenCelsiusandFahrenheittemperatures.IncountrieswhereCelsiusisused,20°Ciscommonlyacceptedasthevalueforroomtemperature.ThefollowingcodecreatesavariablecalledintRoomTempC,andthenassignsitavalueof20:NewRevised2ndEditionOutNOW!BuildYourOwnDatabaseDrivenWebsiteUsingPHP&MySQLFullyupdatedforPHP4.3.InstallationinstructionsforMacOSXFullindexprovidedNewwiderbooksizeEnhancedfontsNewcoverdesignLay-flatspineAllcontentrevisitedDownloadtheFirst4ChaptersFREETellmemoreaboutthistop-sellingbook.$intRoomTempC'CreateavariableintRoomTempC=20'Assignthevariableavalueof20Thekeyword$intheaboveisshortfor$ension,andisusedtotellPHPtocreateavariablewiththenamespecified(inthiscase,intRoomTempC).Why'$ension',youask?Iagree,it'snotthemostobviouschoice,butbasicallyitreferstowhatyou'reaskingPHPtodo.Whencreatingavariable,PHPneedstoassignsomespaceinmemorytostorewhatevervalue(s)willbeplacedinthevariable,andpartofthattaskistofigureoutthesize($ension)ofthespacethatneedstobeallocated.Inanycase,creatingavariableisassimpleastyping$followedbythenameofthevariable.Thesecondlineoftheaboveexampleassignsavaluetothevariablethatwasjustcreated;specifically,itstoresthenumber20inthevariable.Theequalssign(=)iscalledtheassignmentoperatorbecauseitisusedtoassignvaluestovariables.Duringthecourseofthisarticle,you'llmeetmanyotheroperatorsthatdootherweirdandwonderfulthingstovariablesandthevaluestheystore.Youshouldalwayscreateavariablebeforeassigningitavalue,andyou'llusuallywanttoassignthevariableavaluebeforeputtingittouse.Tryingtoassignavaluetoavariablethatdoesnotexist,however,willcausePHPtoautomaticallycreateanewvariablewiththegivenname.Thisiscalledimplicitdeclaration,becauseanewvariableisdeclaredimplicitlyasaresultofyourtryingtoassignavaluetoavariablethatdoesn'texist.Sinceyouarefreetouseimplicitdeclarationforallofyourvariables,youmaybewonderingwhatthepointisofusingthe$commandtocreateeachandeveryvariablebyhand.Theanswerhastodowithhoweasyyouwantittobetofindtypingmistakesinyourcode.PHPprovidesanothercommand,OptionExplicit,whichcausesPHPtodisallowimplicitdeclarationsandinsteaddisplayanerrormessagewheneveryoutrytoassignavaluetoanon-existentvariable.Whywouldyouwantthistohappen?Considerthefollowingexample:$intRoomTempC'CreateavariableintRomTempC=20'Assignthevariableavalueof20Ifyouhaveakeeneye,youmayhavenoticedthatthevariablenameismisspelledonthesecondline.Thisisthekindofmistakethatevenexperiencedprogrammersmakeallthetime.Withimplicitdeclarationenabled,thesecondlinewillcreateanothernewvariablecalledintRomTempCandwillstorethevalueinthatvariableinstead.Now,iftherestofyourscriptexpectsthatvaluetobestoredinintRoomTempC,you'regoingtorunintotrouble.Inalargescript,tracingsuchaproblembacktoonelittletypingmistakecanbeverytimeconsuming.That'swhereOptionExplicitcomesin:OptionExplicit'Disableimplicitdeclaration$intRoomTempC'CreateavariableintRomTempC=20'Assignthevariableavalueof20Thistime,PHPwillreportthetypingmistakeasanillegalimplicitdeclaration,displayinganerrormessa

1 / 8
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功