Capstone: A Multi-File Profile Card Generator

Course 1 · Capstone
Capstone: A Multi-File Profile Card Generator
Bringing together variables, control structures, functions, arrays, strings, superglobals, and includes into one small real project

Every chapter in this course introduced one piece in isolation. This capstone project pulls all of them together into a single small, working program: a profile card generator that takes a person's details from a simulated form submission and produces a formatted, styled summary — split across multiple files, the way a real project would be organised.

The Project Structure

The project is split into three files, each with a single clear job — mirroring the shared-header pattern from Chapter 9:

  • helpers.php — a small library of reusable functions (formatting, validation)
  • profile_card.php — the function that builds a formatted profile card from a data array
  • index.php — reads the "submitted" data, includes the other two files, and renders the final output
helpers.php
<?php // A small reusable helper library — Chapter 5's function/scope material, // Chapter 7's string functions function formatName($name) { return ucwords(trim($name)); } function isValidField($value) { return isset($value) && $value !== ''; } ?>
profile_card.php
<?php // Builds one formatted profile card — Chapter 6's array handling, // Chapter 3's control structures, Chapter 7's sprintf() function buildProfileCard($profile) { $name = formatName($profile['name'] ?? ''); $role = $profile['role'] ?? 'Member'; $skills = $profile['skills'] ?? []; if (!isValidField($name)) { return "⚠ Cannot build a card — missing name."; } $skillList = count($skills) > 0 ? implode(', ', $skills) : 'No skills listed'; return sprintf( "%s\n%s\nSkills: %s", $name, $role, $skillList ); } ?>
index.php
<?php // The entry point — Chapter 8's superglobals, Chapter 9's require_once require_once 'helpers.php'; require_once 'profile_card.php'; // Simulating a submitted $_POST array, as if from a real form $_POST = [ 'name' => ' philip osztromok ', 'role' => 'Web Developer', 'skills' => ['PHP', 'MySQL', 'JavaScript'] ]; $profile = [ 'name' => $_POST['name'] ?? '', 'role' => $_POST['role'] ?? '', 'skills' => $_POST['skills'] ?? [] ]; echo buildProfileCard($profile); ?>
Output
Philip Osztromok
Web Developer
Skills: PHP, MySQL, JavaScript

What Each Chapter Contributed

Nothing in the project above is new — every line traces back to a specific earlier chapter:

  • Chapter 2 (Variables & Type Juggling): $profile, $name, $skillList — variables holding and passing data between functions
  • Chapter 3 (Operators & Control Structures): the if check for a missing name, and the ternary ? : deciding the skill list text
  • Chapter 5 (Functions & Scope): formatName(), isValidField(), and buildProfileCard() — each with its own local scope, parameters, and return value
  • Chapter 6 (Arrays): $profile and $_POST['skills'] as associative and indexed arrays, plus count() and implode()
  • Chapter 7 (Strings): trim(), ucwords(), implode(), and sprintf() for building the final formatted output
  • Chapter 8 (Superglobals): reading $_POST safely with the ?? null coalescing operator
  • Chapter 9 (Includes): require_once to pull the helper library and the card-builder function into index.php
Why require_once was the right choice here, not include
index.php genuinely cannot build a profile card without buildProfileCard() being defined — if profile_card.php failed to load, the whole page should stop with a clear error rather than silently continuing and producing a confusing "call to undefined function" failure further down. That's exactly the require-over-include reasoning from Chapter 9, applied to a real project rather than an abstract rule.

Final Coding Challenge

Final Challenge

Extend buildProfileCard() to also accept an optional "email" key. If present and valid (contains an @ character), append a line "Contact: {email}" to the output; if missing, append "Contact: not provided" instead. Test it with two different simulated $_POST arrays — one with a valid email, one without any email key at all — and echo both results.

📄 View solution

Course Complete

This capstone closes out PHP Fundamentals. From here, PHP Intermediate builds directly on this foundation — sessions and cookies for remembering a visitor between page loads, object-oriented PHP (classes, the same concept the arrays and functions here were quietly building toward), working with a real MySQL database instead of simulated arrays, and proper input validation and sanitisation for handling real, untrusted user input safely.

Course 1 Complete — What You've Learned

  • Ch 1–2: PHP syntax, echo, variables, and PHP's own type-juggling rules
  • Ch 3–4: Operators, if/elseif/else, and all three loop types (for, while, foreach)
  • Ch 5: Functions — parameters, return values, and global vs. local scope
  • Ch 6: Indexed and associative arrays, plus the core array function library
  • Ch 7: The string function library — searching, slicing, replacing, and sprintf formatting
  • Ch 8: Reading external data safely via $_GET, $_POST, and $_SERVER
  • Ch 9: Splitting code across files with include/require and their _once variants
  • Capstone: a real multi-file project combining every one of the above