can't get multiline to work with heredoc
Posted: Sun Oct 04, 2009 7:52 am
I'm working some samples, learning PHP, and I can't get the heredoc construct to output multiline text in the browser.
My samples come from an O'Reilly book and various websites.
Am I doing something wrong?
I'm a mac newbie doing this in Netbeans on the mac with MAMP 1.8.2 installed. Mamp has PHP 5 with Zend Extensions (don't know what that is). I copied the text for index.php to another editor, thinking it might be something with netbeans, but that didn't help.
this code, below, outputs only one line.
the output in the browser looks like this
My samples come from an O'Reilly book and various websites.
Am I doing something wrong?
I'm a mac newbie doing this in Netbeans on the mac with MAMP 1.8.2 installed. Mamp has PHP 5 with Zend Extensions (don't know what that is). I copied the text for index.php to another editor, thinking it might be something with netbeans, but that didn't help.
this code, below, outputs only one line.
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
$variables = "a test variable";
$string = <<< END_OF_STRING
this is a multi-line
string containing variables
and single quotes '
and double quotes "
and slashes \
do not need to be escaped
END_OF_STRING;
echo $string
?>
</body>
</html>
this is a multi-line string containing a test variable and single quotes ' and double quotes " and slashes \ do not need to be escaped