0% found this document useful (0 votes)
9 views

PHP - String Creation Double-Quotes

Double-quotes allow for special escaped characters in strings that single-quotes do not. Escaped characters like newlines, carriage returns, and tabs can be used to format strings but are ignored by HTML. Heredoc syntax allows creating multi-line strings without quotations but requires proper coding to avoid problems.

Uploaded by

Anil Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

PHP - String Creation Double-Quotes

Double-quotes allow for special escaped characters in strings that single-quotes do not. Escaped characters like newlines, carriage returns, and tabs can be used to format strings but are ignored by HTML. Heredoc syntax allows creating multi-line strings without quotations but requires proper coding to avoid problems.

Uploaded by

Anil Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

PHP - String Creation Double-Quotes

We have used double-quotes and will continue to use them as the primary method for forming strings.
Double-quotes allow for many special escaped characters to be used that you cannot do with a single-quote
string. Once again, a backslash is used to escape a character.

PHP Code:
$newline = "A newline is \n";

$return = "A carriage return is \r";

$tab = "A tab is \t";

$dollar = "A dollar sign is \$";

$doublequote = "A double-quote is \"";

Note: If you try to escape a character that doesn't need to be, such as an apostrophe, then the backslash
will show up when you output the string.
These escaped characters are not very useful for outputting to a web page because HTML ignore extra
white space. A tab, newline, and carriage return are all examples of extra (ignorable) white space. However,
when writing to a file that may be read by human eyes these escaped characters are a valuable tool!

PHP - String Creation Heredoc

The two methods above are the traditional way to create strings in most programming languages. PHP
introduces a more robust string creation tool called heredoc that lets the programmer create multi-line strings
without using quotations. However, creating a string using heredoc is more difficult and can lead to problems if
you do not properly code your string! Here's how to do it:

You might also like