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
A line break is a computer language expression that jumps to the next new line. In different languages, the code is different. such as:, "\ n", "Endl" and so on. This article mainly introduces several methods of replacing newline characters in
Convert newline characters to .
Syntax: String nl2br (String string);
return value: String
Function type: Data processing
Content Description
This function converts the newline character to the instruction of the HTML wrapping.
Copy Code code
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/
PHP preg_replace () Regular replacement, unlike JavaScript regular substitution, PHP preg_replace () is the default is to replace all symbol matching conditions of the elements need our program processing data is not always pre-designed database
First, directly filtered out
$reg = Array ("\ r \ n", "\ n", "\ R");$replace = ";$str =str_replace ($reg, $replace, $STR);
So the content will not have to wrap.
Two, become a line wrap
Var_dump ($STR) Print the content out, see in the browser:
One, the following example can remove extra whitespace
The code is as follows
$STR = "This line containstliberal RN with Whitespace.nn";The leading/trailing whitespaceRemove the start and end blank Www.111cn.net$str =
The first type:
Copy CodeThe code is as follows:
? $str = "This is a test \ n";
$patten = Array ("\ n", "\ n", "\ R");
?//replace \ r \ n First, then presence \ n
$str =str_replace ($order, "", $str);
?>
PHP has three ways to solve
1. Use
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.