<?php
$language = 'PHP';
$message = 'Welcome to ' . $language; // 'Welcome to PHP'
$query = 'SELECT firstName, lastName
FROM Users'; // Spans multiple lines
?>
<?php $language = "PHP"; $message = "Welcome to $language"; // 'Welcome to PHP' ?>
<?php
$count = 12;
$item = "flower";
$message1 = "You bought $count $items.";
// 'You bought 12 .'
$message2 = "You bought $count ${item}s.";
// 'You bought 12 flowers.'
?>
heredoc stringsThe ending identifier (MESSAGE; in the example below) *MUST* begin in column 1.
<?php $language = 'PHP'; $message = <<<MESSAGE A heredoc allows you to build multi-line strings in $language. It acts like a double-quoted string and performs variable substitution. MESSAGE; ?>
nowdoc stringsThe ending identifier (MESSAGE; in the example below) *MUST* begin in column 1.
<?php $message = <<<'MESSAGE' A nowdoc also allows you to build multi-line strings. However, no variable substitution takes place. This is similar to a single-quoted string. MESSAGE; ?>