search

Home  >  Q&A  >  body text

Print newline with single quotes in PHP

<p>I tried to use single quotes as much as possible, but I noticed that I can't use n inside single quotes. I know I could enter the newline character directly by pressing enter, but that would break the indentation of my code. </p> <p>When I use single quotes, is there some ASCII character or something I can type that will produce a newline? </p>
P粉436052364P粉436052364487 days ago636

reply all(2)I'll reply

  • P粉883278265

    P粉8832782652023-08-24 22:24:42

    echo 'hollow world' . PHP_EOL;

    Use the constant PHP_EOL then it is also operating system independent.

    reply
    0
  • P粉543344381

    P粉5433443812023-08-24 11:34:16

    No, because single quotes suppress even hex code replacement.

    echo 'Hello, world!' . "\xA";

    reply
    0
  • Cancelreply