There is the following php code:
-
- echo 'hellon';
- echo 'world';
- ?>
Copy the code
The newline character n in the program will be output directly, and the newline cannot be changed correctly. Solution Method: Change single quotes to double quotes:
-
- echo "hellon";
- echo "world";
- ?>
Copy code
In fact, it is the difference between double quotes and single quotes in php, a simple summary Variables in double quotes can be parsed, and single quotes are absolute strings.
Example, three ways to remove line breaks in PHP
-
-
//php Line breaks in different systems - //The implementation of line breaks in different systems is different
- ///n is used in linux and unix
- // mac uses /r
- //window to reflect the difference from linux, it is /r/n
- //so the implementation methods are different on different platforms
- //php There are three methods to solve
$str = str_replace(array("/r/n", "/r", "/n"), "", $str);
- < ;p>//2. Use regular replacement
- $str = preg_replace('//s*/', '', $str);
//3. Use PHP to define it Variables (recommended)
- $str = str_replace(php_eol, '', $str);
- ?>
-
Copy code
|