PHP in the form input box to replace the return of some of the methods summarized, a friend who needs to refer to this article.
The code is as follows |
Copy Code |
? $str = "This is a test n"; $patten = Array ("RN", "n", "R"); ?//Replace RN First, then whether N is present, and the last replacement R $str =str_replace ($order, "", $str); ?> |
?//php there are three ways to solve
The code is as follows |
Copy Code |
1. Use Str_replace to replace line breaks $str = Str_replace (Array ("RN", "R", "N"), "", $str);
2. Use regular replacement $str = preg_replace ('//s*/', ' ', $str);
3. Use PHP-defined variables (recommended) $str = Str_replace (Php_eol, ", $STR); ?/* * 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 = ' RN '; } ElseIf (Stristr ($_server[' http_user_agent '), ' Mac ') { $the _crlf = ' R '; For-old MAC OS } Else { $the _crlf = ' n ';//Right is a big one. } return $the _crlf; }
|
Test code
The code is as follows |
Copy Code |
PHP Gets the line break problem in the form area data
$content =empty ($_post[' content ')? Null:trim ($_post[' content '); if (!empty ($content)) echo str_replace ("R", ' RL ', NL2BR ($content)); echo "R". ' ----------Split Line----------------------'. ' R "; if (!empty ($content)) echo str_replace ("n", ' NL ', NL2BR ($content)); echo "n". ' ----------Split Line----------------------'. ' n "; if (!empty ($content)) echo str_replace ("R", ' RL ', Str_replace ("n", ' NL ', NL2BR ($content))); echo "R". ' ----------Split Line---------------------- '." n "; echo ' Hello '. n ". ' Boys! '; echo ' Hello '. R "." Boys! '; ?>
|
The 1.PHP function nl2br () inserts an HTML newline character before each new line (RN) in the string:
;
The line break under 2.Windows is (RN);
3. In Notepad, R or N has the function of line wrapping;
Note: When the foreground page is displayed, use NL2BR to change the line to
http://www.bkjia.com/PHPjc/632174.html www.bkjia.com true http://www.bkjia.com/PHPjc/632174.html techarticle php in the form input box to replace the return of some of the methods summarized, a friend who needs to refer to this article. Code to copy code as follows? PHP $str =this is a test n; $patten = Arra ...