Q-net > Article Tutorials > Programming design > PHP Delete a string of spaces and newline characters ultimate Method string newline character file encoding Web page encoding hidden characters
the ultimate method of removing spaces and line breaks
PHP has a very good function: NL2BR (), the text box to convert the line to the HTML page
, but how to implement the HTML
is the newline character converted to a line break in a text box? Here are a few ways to help you solve this problem.
The PHP
Here are a few ways to help you solve this problem.The PHP version converts newline characters in HTML to line breaks in text boxes: The code is as follows:function br2nl ($text) { returnpreg_replace('//i ', ',$text);}OrThe code is as
When using FTP software upload to download PHP source files, we occasionally found in the local Windows notepad++ editor written php files, after using FTP uploaded to the linux server, the PHP file line break all lost, resulting in PHP file does
Converts a newline character to
。
Syntax: String nl2br (String string);
return value: String
Function type: Data processing
Content Description
This function converts a newline character to an HTML line-wrapping
Instructions.
Copy the Code code as
Here are a few ways to help you solve this problem.
The PHP version adds the HTMLLine breaks convert to newline characters in text boxes:
Copy the Code code as follows:function Br2nl ($text) {return Preg_replace ('//I
', ', $text);
}
A small package, in fact, different platforms have different implementations. Why are you doing this? It can be a world that is diverse.Originally UNIX and the world had to replace it with/N, but windows in order to reflect their differences. To use/
"Go" PHP removes the use of line breaks and Php_eol variables
About \n,\r,\t?
\ n Soft return:? In Windows, it represents a newline and goes back to the beginning of the next line, only in Linux, UNIX, but not back to the beginning of the next
For example, the following code:
Copy Code code as follows:
Echo ' hello\n ';
echo ' World ';
?>
The newline character in the program is output directly, and the line cannot be wrapped correctly, and the solution is to change
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.