PHP in the form input box line break enter replace _php tutorial

Source: Internet
Author: User
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 ...

  • Related Article

    Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.