Skip to content
← Back to Snippets
Code

Hello World

Outputs a simple Hello World message and shows the safe difference between plain text output and browser-rendered HTML output.

Purpose

Outputs a simple Hello World message and shows the safe difference between plain text output and browser-rendered HTML output.

Snippet details

ContextUtilityLevelProductionCopy-and-paste statusMarked safe after review.

Categories

  • Forms and Validation

Code

<?php

/*
 * Copyright (c) 2026 Jeffery L. Paris <jparis@phpog.com>.
 * Free for personal and internal use. Paid project use requires visible credit
 * to Jeffery L. Paris. Corporate use requires a paid license fee unless a
 * separate written license states otherwise.
 */

/**
 * Hello World.
 *
 * Purpose:
 * Shows the smallest useful PHP output example while keeping browser output
 * escaped at render time.
 *
 * @param string $call_sign Name or label to include in the greeting.
 * @return array Plain message and escaped HTML-safe message.
 */
function ogSnippetHelloWorld(string $call_sign): array {
	$call_sign = trim($call_sign);

	if ($call_sign === '') {
		$call_sign = 'PHPOG developer';
	}

	$message = 'Hello World from '.$call_sign.'.';
	$escaped_message = htmlspecialchars($message, ENT_QUOTES, 'UTF-8');

	return array(
		'plain_text' => $message,
		'html_text' => $escaped_message
	);
}

$greeting = ogSnippetHelloWorld('Rocinante nav deck');

echo $greeting['plain_text'];

echo "
";

echo '<p>'.$greeting['html_text'].'</p>';