Memory App
 



Programming > Php > Basics > String type   ZCE 5.3  |  Patterns  |  Modern Php

Single quotes

Variables are NOT interpreted and replaced.

$a = 'a';

echo $b = '$an'; // outputs $an
(1/3)

Double quotes

Variables are interpreted and replaced.

$a = 'a';

echo $b = "$an"; // output a
(2/3)

Herodoc

Herodoc formating is used for multiple lines. I allowes for the use of quotes without escaping.

$who = "John";
$output = <<<TEST
    She said "This is $who's test"
    on multiple rows
TEST;

echo nl2br($output);
/* 
    She said "This is John's test"
    on multiple rows
*/
Note that the line with the closing identifier must contain no other characters, except possibly a semicolon (;). Also, the first character after the closing identifier must be a newline. https://stackoverflow.com/questions/7581315/php-heredoc-string-rules

Questions
0/0 (80)  
Not Logged