Upload
jimbojsb
View
618
Download
3
Embed Size (px)
DESCRIPTION
Citation preview
Beginning PHPSession #2
November 17, 2010
Josh Butts
Agenda for Today
•Go over Homework #1
•Include & Require
•Errors & Warnings
•String Functions
•Writing Your Own Functions
Corrections
•Use “echo $foo”, not “echo($foo)”
•I think we forgot to talk about code comments, so lets do that now
Comments
A note on constructs vs.
functions•A language construct is a core part of the language, like “true”, “include” and “isset”
•Some things in PHP behave like functions, but are actually language constructs
String Functions
•You’ll use these all the time
•The internet deals in strings
•Much like array functions, there are quite a few
strlen()
•How long is a string, in characters?
•As long as this isn’t UTF-8-ish
substr()
•Get a smaller part of the whole string
•Operates by “index”
str_replace()
•search and replace strings within strings
•use arrays for extra power
strpos()
• Finds out the “index” location of a string within a string
• Commonly used to find if a string exists within another
Changing Case
explode()
•Split up a string on certain characters and give back an array of the pieces
implode()
•Build a string from an array
Functions
•Functions are ways to encapsulate & organize your code
•Hundreds of built-in functions
•Calculate values, perform repetitive tasks, output data
Write Your Own Functions
Include
•Load another PHP file into the current contexts
•Executes that code as if it were in the current file
•Gives a warning if the file is not found
Include_Once
•The same as include, except keeps track of if you’re already included the file and only includes it once
•Use but don’t abuse, there is an implicit speed penalty for doing this
Require
•Functions the same way as include except gives a fatal error if the file is not found
•Tends to be used for system components vs. small output snippets
•Require_once == include_once