How to Use Expression of Multiline String in PHP

Before starting the Expression of Multiline String in PHP, we must know What is Multiline String and what is the use of this expression in PHP. Staring is the set of characters, where characters are also known as bytes. This means PHP supports 256-character set in a string.

Introduction to Multiline String in PHP

Basically, multiline string means we print the big statement (or set of strings) line by line. For example, if we want to print a variable that defines some set of strings and write it line by line into the code. Check below example,

Output: This is the
three-line
set of strings.

Here are some easy ways to use the multiline string in PHP,

  1. Use HEREDOC string method.
  2. By Using concatenation assignment operator.

Note: If you want to check the proper output of the above code by using your local server, you have to run the complete code on CMD or XAMPP Shell. If you do not know how to run PHP code on the Command line, you can check here Execute PHP File From Command Line.

Use HEREDOC String Method to Use Multiline String

PHP has two inbuilt methods HEREDOC and NOWDOC to handle multiline strings. HEREDOC has also it syntax <<<.

Here is the example of multiline PHP string by using HEREDOC,

Output:

Example of Multiline String in PHP
Example of Multiline String in PHP

By Using the Concatenation Assignment Operator

On the above code, we use PHP_EOL for the next line. PHP_EOL stands for PHP End of line that is majorly used for change the line of the staring. To check the output of the above code you have to run it on the command line of your OS.

Output:

Example of PHP Concatenation Operator
Example of PHP Concatenation Operator

This is the complete reference of PHP multi-line String with syntax and examples. The above codes are also shown us how we can define a multi-line string in PHP script.

If you get any issues please let me know on the comment.

You can check more about it from PHP official site PHP: Strings – Manual.

Some bonus points,

If you run it on the browser it will not be working properly.

EOD = End Of Data,
EOT = End of Text

Also Read:

Happy Coding..!

Was this article helpful?
YesNo
My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH, my native place in Odisha. I am a Web Programmer by profession and working on more than 50 projects to date. My passion is working on the web-based project using PHP and relate to all CMS and frameworks which is based on PHP.
Posts created 181

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top
mariobet - supertotobet - escort - milanobet giriş - gizabet giriş -
perabet giriş
- betkanyon giriş -

jojobet giriş

We are now accepting guest posting and creation of back-links.
This is default text for notification bar