← All learning materials
PHP & Routing · 25 MIN READ · DEVELOPER GUIDE

PHP syntax and reusable page components

Learn variables, arrays, functions, includes and safe HTML output in this project.

Learning progress is saved in this browser when local storage is available.

Read the syntax

PHP blocks begin with <?php. Variables start with $, statements end with a semicolon, associative arrays use key => value, and -> accesses an object method or property. The ?? operator gives a fallback when a value is missing or null. Function type declarations document expected inputs and outputs.

Share page components

require_once loads a dependency once and stops execution if it cannot be loaded. include renders reusable markup such as a navbar or footer. __DIR__ anchors an include to its own file directory rather than the caller working directory.

Keep output in the correct context

Use htmlspecialchars with ENT_QUOTES and UTF-8 when inserting plain text into HTML. Use json_encode for JSON. Escape on output and validate on input; escaping a heading does not validate a database identifier or a redirect destination.

Syntax in practice

A focused learning example. Read the referenced source file for its full application context.

<?php
function label(array $item): string {
    return (string) ($item['title'] ?? 'Untitled');
}
?>
<h2><?= htmlspecialchars(label(['title' => 'Studio']), ENT_QUOTES, 'UTF-8') ?></h2>
PUT IT INTO PRACTICE

Try it yourself

Add a local heading containing < and & and confirm it appears as text, not HTML.

Work on a development copy, then explain what changed and how you verified it.

Project file map

Find these paths in your local WebsHigher checkout. Source paths are references, not public downloads of application code.

  • includes/feature-template-showcase.php
  • includes/solution-distinct-templates.php
  • academy.php

Keep learning

Start here: the WebsHigher codebase →Run the project locally →Build responsive pages with HTML and CSS →
Get Started