This article describes how to solve the problem of invalid line breaks and line breaks in php strings. it is actually a problem of using PHP double quotes and single quotes. For more information, see the following code:
The code is as follows: Echo 'hello \ n ';
Echo 'world ';
?>
The line break \ n in the program will be directly output and cannot wrap correctly. the solution is to change single quotes to double quotation marks:
The code is as follows: Echo "hello \ n ";
Echo "world ";
?>
That's all! It is actually the difference between PHP double quotes and single quotes. Simply put, variables in double quotes can be parsed. single quotes are absolute strings.
Appendix: three methods for removing line breaks in PHP
The code is as follows: // Line feed for different php systems
// The implementation of line feed varies with systems.
// In linux and unix/n
// For MAC/r
// Window is/r/n to reflect differences from linux
// The Implementation methods on different platforms are different.
// Php has three solutions
// 1. use str_replace to replace the line feed.
$ Str = str_replace (array ("/r/n", "/r", "/n"), "", $ str );
// 2. use regular expression replacement
$ Str = preg_replace ('// s */', '', $ str );
// 3. use the variables defined in php (recommended)
$ Str = str_replace (PHP_EOL, '', $ str );
?>