In the html form, in textarea, we press the carriage return and line feed to display some asc or special characters, but we cannot see them. if we do not convert the output text, there is no typographical layout, the following is a summary of some examples in this article. php get textare... in the html form, in textarea, we press the carriage return and line feed to display some asc or special characters, but we cannot see them. if we do not convert the output text, there is no typographical layout, the following is a summary of some examples in this article.
It is very simple for php to obtain the textarea value. The carriage return behavior \ r \ n is shown in the following example.
The HTML code is as follows:
The PHP 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); // replace line breaks with echo $ str1;
All code:
$ 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 a dz Forum. if you don't talk about it much, go to the code:
$ Names = preg_split ('/\ r \ n/', $ _ POST ['textarea ']); foreach ($ names as $ name) {// todo something eg: the echo $ name;} value is very simple, so the value assignment can be less simple. the code is as follows: $ vals = get_from_mydb (); $ tmp = ''; foreach ($ vals as $ val) {$ tmp. = $ val.'
';}
"" And"
"What does it mean? I believe everyone can see it. In fact, the carriage return in textarea is converted into a character" \ n, therefore, php processes the carriage return in textarea and processes the "\ n" in the character ".
Article address:
Reprint at will ^ please include the address of this article!