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 Str_replace to replace line breaks
$str = Str_replace (Array ("\ r \ n", "\ r", "\ n"), "", $str);
2. Use regular replacement
$str = preg_replace ('//s*/', ' ', $str);
3. Use PHP-defined variables (recommended)
$str = Str_replace (Php_eol, ", $STR);
Copy CodeThe code is as follows:
/*
* Get the user's operating system line break, \ n
* @access Public
* @return String
*/
function Get_crlf ()
{
if (Stristr ($_server[' http_user_agent '), ' Win ')
{
$the _crlf = ' \ r \ n ';
}
ElseIf (Stristr ($_server[' http_user_agent '), ' Mac ')
{
$the _crlf = ' \ r '; For-old MAC OS
}
Else
{
$the _crlf = ' \ n ';//The right to be significant
}
return $the _crlf;
}
Note: When the foreground page is displayed, use NL2BR to change the line to
The second example illustrates:
Find an interesting thing to do:
$text = "AAAA
CCC ";
$text =str_replace (' \ n ', "", $text);
$text =str_replace (' \ R ', "", $text);
$text =str_replace (' \ r \ n ', ' ", $text);
Normally, the above code should be able to replace the line break.
But in fact it is not!
Very depressed, tried many times, is not working.
And finally changed it.
Copy CodeThe code is as follows:
$text =str_replace ("\ n", "", $text);
$text =str_replace ("\ R", "", $text);
$text =str_replace ("\ r \ n", "", $text);
Incredibly all OK ~ ~, the original is double quotation marks, single quotation mark problem!!
Double quotation marks than single quote efficiency almost, because the double quotation marks in the process of PHP parsing, will also determine whether there are variables, single quotation marks will not have this judgment, so generally speaking, no variables involved in the case, I would use single quotation marks, did not expect this time to replace the newline character, with single quotation mark incredibly not
Finally write a sentence
Copy CodeThe code is as follows:
$order = Array ("\ n", "\ n", "\ R");
$replace = ";
$text =str_replace ($order, $replace, $text);
This replaces the line break!
http://www.bkjia.com/PHPjc/326211.html www.bkjia.com true http://www.bkjia.com/PHPjc/326211.html techarticle The First: Copy the code as follows: php? $str = "This is a test \ n"; $patten = Array ("\ r \ n", "\ n", "\ R"); Str_replac ...