I know I can make a new variable by simply saying $var = "stuff"
, but how would I make one like this:
<?php
$var = ?>
<html>
<head>
</head>
<body>
</body>
</html>
<? ; ?>
Do you see what I am getting at? Is there a way to create a variable without having to be restrictive and using = "";
Thanks for your help.
EOD = End Of Data, EOT = End of Text.
We can create a string in PHP by enclosing the text in a single-quote. It is the easiest way to specify string in PHP. For specifying a literal single quote, escape it with a backslash (\) and to specify a literal backslash (\) use double backslash (\\).
Escape Sequences In PHP, an escape sequence starts with a backslash \ . Escape sequences apply to double-quoted strings. A single-quoted string only uses the escape sequences for a single quote or a backslash.
Sounds like a job for Heredoc
$var = <<<HTML
<html>
<head>
</head>
<body>
</body>
</html>
HTML;
Note, that the end token (here HTML;
) must be on a line for itself without any leading or trailing whitespaces (except the newline at the end).
Additional you can just put everything into a string like usual, but with newlines
$var = '<html>
<head>
</head>
<body>
</body>
</html>';
Or add newline characters yourself
$var = '<html>' . PHP_EOL;
$var .= '<head>' . PHP_EOL;
$var .= '</head>' . PHP_EOL;
$var .= '<body>' . PHP_EOL;
$var .= '</body>' . PHP_EOL;
$var .= '</html>';
or
$var = "<html>\n<head>\n</head>\n<body>\n</body>\n</html>";
If you want to parse PHP variables (like you would with a double quote), use the HEREDOC syntax.
If you want no parsing of variables, use the NOWDOC syntax.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With