happy cat image

Start Web Coding

Your First step toward web coding,
Start Web Coding

change UI

using here doc

Use here-doc when declaring a value in a variable, regardless of the line of code.

here doc how to use

$string = <<<EOL
string string blah blah
string string blah blah
string string blah blah
EOL;

In the code above, you entered EOL starting with <<< before entering the value to assign.
This means that you start assigning values ​​regardless of the line of code.
And once you're done, enter EOL one more time.
Here is an example of using the here doc to assign a value to a variable and output it.

<?php
    $hereDoc = <<<EOL
Hello?<br>
Good to see you?<br>
My homepage letting me use really thank you ! <br>
Go !!<br>
Not giving up let <br>
Let's live and die nicely!<br>
EOL;

    echo $hereDoc;
?>

Here is the resulting image

You can also put variables. Like this:

<?php
    $hello = "안녕하세요?";
    $hereDoc = <<<EOL
Hello?<br>
Good to see you?<br>
My homepage letting me use really thank you ! <br>
Go !!<br>
Not giving up let <br>
Let's live and die nicely!<br>
EOL;

    echo $hereDoc;
?>

Here is the resulting image.

The EOL used in the here doc is called the Termination ID, and there are EOT, END, and EOT in addition to EOL. Using different things will not work and should start and end with the same thing.

강좌로 돌아가기