Download and Preview : Introduction To PHP University Of Michigan
Report CopyRight/DMCA Form For : Introduction To PHP University Of Michigan
Introduction to PHPDr Charles Severancewww php intro com About the PHP Language Syntax is inspired by C. Curly braces semicolons no signficant whitespace Syntax inspired by perl Dollar signs to start variable names associative Extends HTML to add segments of PHP within anHTML file . Philosphy of PHP You are a responsible and intelligentprogrammer You know what you want to do Some flexibility in syntax is OK style choices. Lets make this as convienent as possible Sometimes errors fail silently h1 Hello from Dr Chuck s HTML Page h1 echo Hi there n answer 6 7 .echo The answer is answer what echo was the question again n p Yes another paragraph p h1 Hello from Dr Chuck s HTML Page h1 echo Hi there n . answer 6 7 echo The answer is answer what echo was the question again n p Yes another paragraph p PHP From the Command. You can run PHP fromthe command line echo Hello World the output simply echo n comes out on the It does not have to be.part of a request response cycle abstract Key Wordsand array as break casecatch class clone const continue.declare default do else elseif enddeclare endfor endforeach endifendswitch endwhile extends final forforeach function global goto ifimplements interface instanceof.namespace new or private protectedpublic static switch this throw try usevar while http php net manual en reserved php Variable Names. Start with a dollar sign followed by a letter orunderscore followed by any number of letters numbers or underscores Case matters abc 12 abc 12 . total 0 2php 0 largest so far 0 bad punc 0 http php net manual en language variables basics php Variable Name Weirdness. Things that look like variables but are missing adollar sign can be confusing x 2 x 2 y x 5 y x 5 print y print x .5 Parse error Expressions Completely normal like other languages More agressive implicit type conversion x 15 27 .echo x 42echo n echo is a language construct x 15 27 can be treated like a echo x function with one parameter echo n .Without parenthesis it echo x n accepts multiple parameters print x print n print is a function only one print x parameter but parenthesis print n .are optional so it can look like a language construct Conditional if Logical operators and or Curly braces. ans 42 if ans 42 print Hello world n else Hello World print Wrong answer n . Whitespace does not ans 42 if ans 42 print Hello world n print Wrong answer n . php ans 42 if ans 42 print Hello world n else print Wrong answer n What Style do You Prefer ans 42 php if ans 42 . ans 42 if ans 42 print Hello world n print Hello world n else elseprint Wrong answer n . print Wrong answer n Associative Arrays Like Python Dictonaries Lists but more Can be key value or simply indexed by Ignore two dimensional arrays for now . Integer Indices stuff array Hi There echo stuff 1 n Integer Indices stuff array . stuff Hello stuff World echo stuff 1 n Integer Indices stuff array . stuff 2 Hello stuff 9 World echo stuff 9 n Key Value stuff array name Chuck . course SI664 echo stuff course n Dumping an Array The function print r dumps out PHP data it isused mostly for debugging. stuff array name Chuck course SI664 print r stuff name Chuck course SI664. Dumping an Array The function print r dumps out PHP data it isused mostly for debugging stuff array stuff 2 Hello . stuff 9 World print r stuff 2 Chuck 9 SI664 var dump vs print r. stuff array name Chuck course SI664 var dump stuff array 2 name .string 5 Chuck course string 5 SI664 http stackoverflow com questio... var dump is more. thing FALSE echo One n print r thing echo Two n Onevar dump thing Two. bool false http stackoverflow com questio... Looping Through an Array stuff array name Chuck course SI664 .foreach stuff as k v echo Key k Val v n Key name Val ChuckKey course Val SI664 Variable Name Weirdness. Things that look like variables but are missing adollar sign as an array index are unpredictable y array x Hello print y x String literals can use single quotes or double quotes. The backslash is used as an escape character Strings can span multiple lines the newline is part ofthe string In double quoted strings variable values arehttp php net manual en .language types string phpecho this is a simple string echo You can also have embedded newlines instrings this way as it isokay to do . Outputs Arnold once said I ll be back echo Arnold once said I ll be back Outputs This will not expand n a newlineecho This will not expand n a newline Outputs Variables do not expand either.echo Variables do not expand either php Quoteecho this is a simple string n echo You can also have embedded newlines instrings this way as it is.okay to do Outputs This will expand a newlineecho This will expand na newline Outputs Variables do 12. expand 12 echo Variables do expand n echo This is a test This is a c style comment This is a multi line commentyet another line of comment .echo This is yet another test echo One Final Test This is a shell style commenthttp php net manual en languag... syntax comments php This is a sprint through the language features of. Acknowledgements ContributionsContinue new Contributors and Translators hereThese slides are Copyright 2010 Charles R Severance www dr chuck com as part of www php intro com and madeavailable under a Creative Commons Attribution 4 0 License .Please maintain this last slide in all copies of the document tocomply with the attribution requirements of the license If youmake a change feel free to add your name and organizationto the list of contributors on this page as you republish thematerials .Initial Development Charles Severance University ofMichigan School of InformationInsert new Contributors and Translators here including namesIntroduction to PHP Dr. Charles Severance www.php-intro.com Note from Chuck. If you are using these materials, you can remove my name and URL from this replace it with your own, but please retain the CC-BY logo on the first page as well as retain the entire last page when you remix and republish these slides.