PHP: String Syntax

By Xah Lee. Date: . Last updated: .

Apostrophe Delimiter

Use APOSTROPHE delimiter for literal string.

<?php
echo 'hi there.
something';
?>

QUOTATION MARK Delimiter

Use QUOTATION MARK delimiter for interpreted string.

When using QUOTATION MARK, any variables in the following forms are evaluated and its value used.

backslash has special meaning, called escape sequence. \n is a new line.

<?php
$x = 4;
echo "I have $x apples";
// I have 4 apples
?>
<?php
// can contain Unicode characters
echo "α β and ♥";
?>
<?php
// can contain literal line break
echo "some
thing";
?>
<?php
$x = 3;
$y = 4;
echo "{$x} cats {$y} dogs";
# 3 cats 4 dogs
?>

Escape Sequence

the following characters has special meaning.

PHP, String