This article mainly introduces how php can get the value of textarea and process the line break of carriage return, which involves conversion and processing of special characters. For more information, see
This article mainly introduces how php can get the value of textarea and process the line break of carriage return, which involves conversion and processing of special characters. For more information, see
This example describes how php can obtain the textarea value and process the carriage return and line feed. Share it with you for your reference. The specific implementation method is as follows:
In general, in an html form, in textarea, we press the carriage return and line feed to encode some ascii or special characters. If we do not convert the output text, it is not typographical.
It is very simple for php to obtain the textarea value. The carriage return Behavior \ r \ n is shown in the following example.
HTML code:
The Code is as follows:
PHP code:
The Code is as follows:
$ Str = $ _ GET ['test'];
Echo $ str .'
';
$ Arr = explode ("\ n", $ str );
Print_r ($ arr );
Echo count ($ arr ).'
'; // Number of carriage returns
$ Str1 = nl2br ($ str); // press enter to change to line feed
Echo $ str1;
All code:
The Code is as follows:
<? Php
$ Str = $ _ GET ['test'];
Echo $ str .'
';
$ Arr = explode ("\ n", $ str );
Print_r ($ arr );
Echo count ($ arr ).'
'; // Number of carriage returns
$ Str1 = nl2br ($ str); // press enter to change to the default function of line feed.
Echo $ str1;
?>
Let's take a look at the example in the dz forum. Let's just move on to the Code:
The Code is as follows:
$ Names = preg_split ('/\ r \ n/', $ _ POST ['textarea ']);
Foreach ($ names as $ name ){
// Todo something eg: echo $ name;
}
The value is very simple, so the value assignment is not that easy to output line breaks in textarea.
The Code is as follows:
$ Vals = get_from_mydb ();
$ Tmp = '';
Foreach ($ vals as $ val ){
$ Tmp. = $ val .'';
}
What does "" and "" mean?
I believe everyone can see that, in fact, the carriage return in textarea becomes "\ n", so php processes the carriage return in textarea as "\ n" in the character ".
I hope this article will help you with PHP programming.