PHP only supports a 256-character set. PHP does not support Unicodes PHP string can be as large as 2GB. |
Variables and escape sequences for special characters are not expanded in
Single quoted strings. If we have a single quote within the string we escape it using / If there is a \ (forward-slash) it can be escaped by // (double slash) Escape sequences like \r \n are not expanded in Single quotes strings. |
<?php $var = "Mike"; echo 'Hello, <br>'; echo '"Double quotes here have no issues."<br>'; echo 'We can have multi-line Single quote strings.<br>'; echo 'Newline sequence \n wont expand.<br>'; echo 'I\'m here!<br>'; echo 'My Name is $var, err!!, variables won\'t expand.<br>'; ?>
Output
Hello, "Double quotes here have no issues." We can have multi-line Single quote strings. Newline sequence \n wont expand. I'm here! My Name is $var, err!!, variables won't expand.
Escape sequences are expanded in Double quoted Strings Variable names are expanded in Double quoted Strings |
<?php $var = "Mike"; echo "Hello, <br>"; echo "'Single quotes here have no issues.'<br>"; echo "We can have multi-line Double quote strings.<br>"; echo "Newline sequence \n is expand in Double quoted strings.<br>"; echo "He is the \"Man\"!<br>"; echo "My Name is $var, Wow!!, variable names do get expanded in Double quoted strings. <br>"; ?>
Output
Hello, 'Single quotes here have no issues.' We can have multi-line Double quote strings. Newline sequence is expand in Double quoted strings. He is the "Man"! My Name is Mike, Wow!!, variable names do get expanded in Double quoted strings.
<?php $str = <<<EOD This is an example of heredoc spanning multiple lines. EOD; echo $str; ?>
Output
This is an example of heredoc spanning multiple lines.
Only difference between heredoc's and nowdoc's syntax is that nowdoc's starting identifier is surrounded by single quotes. |
<?php $name = "Mike"; //Heredoc example echo <<<EOT My name is $name I love PHP. EOT; echo "<br>"; //Nowdoc example echo <<<'EOT' My name is $name I love PHP. EOT; ?>
Output
My name is Mike I love PHP. My name is $name I love PHP.
To sum up, Nowdoc behave just like "Single Quoted Strings" and, Heredocs behave just like "Double Quoted Strings". |