WhatisPHP?(5.1.2)
PHPstandsfor"PHPHypertextPreprocessor"aserver-sidescriptinglanguageusedtomakewebpagesdynamic:providedifferentcontentdependingoncontextinterfacewithotherservices:database,e-mail,etcauthenticateusersprocessforminformationPHPcodecanbeembeddedinXHTMLcode
LifecycleofaPHPwebrequest(5.1.1)
browserrequestsa.htmlfile(staticcontent):serverjustsendsthatfilebrowserrequestsa.phpfile(dynamiccontent):serverreadsit,runsanyscriptcodeinsideit,thensendsresultacrossthenetworkscriptproducesoutputthatbecomestheresponsesentback
WhyPHP?
Therearemanyotheroptionsforserver-sidelanguages:RubyonRails,JSP,ASP.NET,etc.WhychoosePHP?freeandopensource:anyonecanrunaPHP-enabledserverfreeofchargecompatible:supportedbymostpopularwebserverssimple:lotsofbuilt-infunctionality;familiarsyntaxavailable:installedonUW'sservers(Dante,Webster)andmostcommercialwebhosts
Hello,World!
Thefollowingcontentscouldgointoafilehello.php:
Hello,world!
ablockorfileofPHPcodebeginswithPHPstatements,functiondeclarations,etc.appearbetweentheseendpoints
ViewingPHPoutput
youcan'tviewyour.phppageonyourlocalharddrive;you'lleitherseenothingorseethePHPsourcecodeifyouuploadthefiletoaPHP-enabledwebserver,requestingthe.phpfilewillruntheprogramandsendyoubackitsoutput
5.2:PHPBasicSyntax
5.1:Server-SideBasics5.2:PHPBasicSyntax5.3:EmbeddedPHP5.4:AdvancedPHPSyntax
Consoleoutput:print(5.2.2)
print"text";print"Hello,World!\n";print"Escape\"chars\"aretheSAMEasinJava!\n";print"Youcanhavelinebreaksinastring.";print'Astringcanuse"single-quotes".It\'scool!';
Hello,World!Escape"chars"aretheSAMEasinJava!Youcanhavelinebreaksinastring.Astringcanuse"single-quotes".It'scool!
somePHPprogrammersusetheequivalentechoinsteadofprint
Variables(5.2.5)
$name=expression;$user_name="PinkHeartLuvr78";$