Build useful things with PHP: forms, files, JSON and real databases, safely and step by step.
- 28 lessons
- 7 units
- 4 h 26 m in all
- £0, for good
what’s inside.
For people who finished Level 1, or can already write small programs with variables, decisions, loops and functions.
PHP Level 2 picks up where Level 1 ended. In 28 lessons you label and sort data, format text, handle pretend form posts safely, save files and JSON, store data in an SQLite database with PDO, and use types and exceptions to catch mistakes early. It ends with a level check: a guestbook stored in SQLite.
every lesson goes the same way.
- meet it
- guess first
- your turn
- fix it
- nailed it
unit 1
Arrays with labels
Label your data, look it up by name, and pack records together.
- Keys instead of numbers8 minLabel each value in an array and find it by its label.
- Keys and values in a loop8 minWalk through every label and value, and keep totals the short way.
- Is it there?9 minCheck for a key before you read it, and remove the ones you are done with.
- Arrays inside arrays9 minStore a whole list of records, then pick out exactly the facts you need.
unit 2
Arrays at work
Sort, change and sift whole arrays in a single line.
- Sorting8 minPut a list in order, and keep labels stuck to their values.
- Change every item9 minRun a tiny function on every item and collect the answers.
- Keep only some9 minSift an array so only the items you want are left.
- Sorting your own way10 minSort records by price, length or anything else you choose.
unit 3
Text in shape
Split, search and format text so it reads well.
- Splitting text9 minCut a line of text into pieces and unpack them into variables.
- Formatting with sprintf10 minShow prices, scores and tables exactly the way you want.
- Searching inside text10 minCheck what a string holds, find where, and cut out the part you need.
- One thing or another8 minChoose between two words inside a single line.
unit 4
Visitors and forms
Take what visitors send, check it, and show it safely.
- A pretend request9 minRead the answers a visitor sends, the way a real website does.
- Checking what came in10 minCheck every answer and tell the visitor everything that needs fixing.
- Filters do the fiddly checks9 minCheck emails and whole numbers with PHP's ready-made rules.
- Escaping output10 minShow a visitor's text on a page without letting it take over.
unit 5
Remember things
Keep data between page visits and between runs.
- Sessions9 minRemember a visitor's basket as they move from page to page.
- Writing and reading a file9 minSave text in a file and read it back, even after your program ends.
- Reading line by line9 minCheck a file is there, then work through it one line at a time.
- Saving data as JSON10 minTurn whole arrays into text, save them, and load them back.
unit 6
Databases
Store, find and change data with SQLite and PDO.
- A database in your program11 minMake a table, fill it with rows and read them back.
- Getting rows back10 minAsk for exactly the rows you want, in the order you want.
- Placeholders keep you safe11 minPut visitors' text into SQL without letting it take control.
- Changing and counting rows11 minGive rows an ID, then update or delete exactly the ones you mean.
unit 7
Safer code
Declare types, throw clear errors and catch them on purpose.
- Type declarations10 minTell PHP what each function takes in and hands back.
- Throwing an exception9 minStop a function with a clear message when it is handed nonsense.
- Catching an exception10 minTurn a crash into a friendly message and keep the program running.
- Putting it all together12 minSplit an app into small typed functions that each do one job.