how to remove new lines and returns from php string?

后端 未结 10 1118
孤城傲影
孤城傲影 2020-12-24 01:06

A php variable contains the following string:

text

text2

  • item1
  • item2
10条回答
  •  抹茶落季
    2020-12-24 01:41

    You have to wrap \n or \r in "", not ''. When using single quotes escape sequences will not be interpreted (except \' and \\).

    The manual states:

    If the string is enclosed in double-quotes ("), PHP will interpret more escape sequences for special characters:

    • \n linefeed (LF or 0x0A (10) in ASCII)

    • \r carriage return (CR or 0x0D (13) in ASCII)\

    • (...)

提交回复
热议问题