Geek Austin PHP Class - Session 2

707 views
650 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
707
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
17
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Geek Austin PHP Class - Session 2

  1. 1. Beginning PHP Session #2 November 17, 2010 Josh Butts
  2. 2. Agenda for Today • Go over Homework #1 • Include & Require • Errors &Warnings • String Functions • WritingYour Own Functions
  3. 3. Corrections • Use “echo $foo”, not “echo($foo)” • I think we forgot to talk about code comments, so lets do that now
  4. 4. Comments
  5. 5. 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
  6. 6. String Functions • You’ll use these all the time • The internet deals in strings • Much like array functions, there are quite a few
  7. 7. strlen() • How long is a string, in characters? • As long as this isn’t UTF-8-ish
  8. 8. substr() • Get a smaller part of the whole string • Operates by “index”
  9. 9. str_replace() • search and replace strings within strings • use arrays for extra power
  10. 10. strpos() • Finds out the “index” location of a string within a string • Commonly used to find if a string exists within another
  11. 11. Changing Case
  12. 12. explode() • Split up a string on certain characters and give back an array of the pieces
  13. 13. implode() • Build a string from an array
  14. 14. Functions • Functions are ways to encapsulate & organize your code • Hundreds of built-in functions • Calculate values, perform repetitive tasks, output data
  15. 15. WriteYour Own Functions
  16. 16. 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
  17. 17. 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
  18. 18. 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

×