0

I am running php 5.4.16 on CentOS7. I am trying to create a multiline file. According to the php syntax I have it correct, but it does not honor the newline. Right now I am going back to basic and just using the example on the php site, and it still does not work. What am I missing? https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

my output is : My name is "MyName". I am printing some Foo.Now, I am printing some Bar2.This should print a capital 'A': A

 echo <<<EOT
    My name is "$name". I am printing some $foo->foo.
    Now, I am printing some {$foo->bar[1]}.
    This should print a capital 'A': \x41
    EOT;
    ?>
user2236794
  • 441
  • 3
  • 7
  • 22
  • 2
    What do you mean by `newline`? Do you want a line break on the output? If so, insert one. – GetSet Jan 09 '20 at 15:59
  • I would like it to display the way it is. Meaning after "foo." starts a newline and after "}." another newline. Unless I read the documentation wrong that is how it should work. – user2236794 Jan 09 '20 at 16:02
  • 1
    Are you viewing the result on the command line, or in a browser? On the command line, it should have line breaks alright. In a browser it won't unless you prepend a `header('Content-Type:text/plain');` or use `
    `s as line breaks.
    – Damocles Jan 09 '20 at 16:06
  • In HTML a newline would be `
    `. On console, a newline would be `\n`. As such, how is the PHP to implicitly know what you mean (logically) by newline. I think you are going to have to explicitly insert the newline characters you desire.
    – GetSet Jan 09 '20 at 16:07
  • 1
    Please upgrade PHP as soon as possible. This version hasn't been supported in ages. – Dharman Jan 09 '20 at 16:41
  • If the output you're referencing is in the browser, you can press Ctrl+U to open the source code (Windows, Linux) or Option+Command+U in Safari on Mac. In the source code, you'll see the text output, likely with the newlines. – snwflk Jan 09 '20 at 20:02

0 Answers0