附录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