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

Heredoc/Nowdoc: Echo EOT Hello World. Goodbye! Eot // Output:-// Hello World. // Goodbye!

Heredoc and nowdoc syntaxes in PHP allow defining strings over multiple lines by using an identifier to mark the start and end of the string. They are useful when long strings are needed. The identifier must be unique and cannot appear inside the string. Heredoc delimits the string with the identifier while nowdoc does not interpret variables and escapes in the string.

Uploaded by

Narayan Mishra
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)
33 views

Heredoc/Nowdoc: Echo EOT Hello World. Goodbye! Eot // Output:-// Hello World. // Goodbye!

Heredoc and nowdoc syntaxes in PHP allow defining strings over multiple lines by using an identifier to mark the start and end of the string. They are useful when long strings are needed. The identifier must be unique and cannot appear inside the string. Heredoc delimits the string with the identifier while nowdoc does not interpret variables and escapes in the string.

Uploaded by

Narayan Mishra
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

Constant

Heredoc/Nowdoc
So what about the heredoc and nowdoc syntaxes? They provide an alternative way of
defining strings in PHP. They are particularly useful when we need to define a string over
multiple lines.

They work by defining an identifier that will mark the start and end of the string. The
identifier can be any alphanumeric value following the same rules we’d use for variable
names. One important thing to note with the identifier is that as of PHP 7.3 you need to make
sure that it does not appear within the string itself.

Here’s an example of a heredoc.

echo <<<EOT
Hello World.
Goodbye!
EOT;
// Output:-
// Hello World.
// Goodbye!

28. What is PHP heredoc used for?


A. allows creating single line of string without using quotations
B. allows creating multiple lines of string without using quotations

C. allows creating multiple lines of string with quotations


D. allows creating single lines of string with using quotations
Which function is used to Strip whitespace (or other characters) from the beginning and end
of a string?
A. trim_str
B. strip_str

C. strip
D. trim

You might also like