Print newline in PHP in single quotes

前端 未结 12 1277
野性不改
野性不改 2020-11-28 21:33

I try to use single quotes as much as possible and I\'ve noticed that I can\'t use \\n in single quotes. I know I can just enter a newline literally by pressing return, but

12条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 22:01

    FYI it is possible to get newlines into strings without double quotes:

    printf('Please%1$sgive%1$sme%1$snewlines%1$s', PHP_EOL);
    

    Which may be useful If your irrational fear of double quotes knows no bounds. Though I fear this cure may be worse than the disease.

提交回复
热议问题