Nowdoc Syntax for Multi-line Strings
Demonstrates nowdoc syntax for literal multi-line strings where dollar signs and variable-looking text remain unchanged.
Purpose
Demonstrates nowdoc syntax for literal multi-line strings where dollar signs and variable-looking text remain unchanged.
Snippet details
ContextStringLevelPracticalCopy-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.
*/
/**
* Nowdoc Syntax for Multi-line Strings.
*
* Purpose:
* Builds a literal multi-line string without variable interpolation.
*
* @return string Literal multi-line message body.
*/
function ogSnippetNowdocSyntax(): string {
$message = <<<'MISSION'
Captain: $captain_name
Ship: $ship_name
Status: Literal text preserved for a training record.
MISSION;
return trim($message);
}
$nowdoc_message = ogSnippetNowdocSyntax();
echo $nowdoc_message;