how to remove new lines and returns from php string?

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

A php variable contains the following string:

text

text2

  • item1
  • item2
10条回答
  •  半阙折子戏
    2020-12-24 01:43

    Something a bit more functional (easy to use anywhere):

    function replace_carriage_return($replace, $string)
    {
        return str_replace(array("\n\r", "\n", "\r"), $replace, $string);
    }
    

    Using PHP_EOL as the search replacement parameter is also a good idea! Kudos.

提交回复
热议问题