Php obtains the textarea value and processes the carriage return and line feed method. textarea carriage return and line feed _ PHP Tutorial

Source: Internet
Author: User
Php obtains the textarea value and processes the carriage return and line feed method. textarea returns the line feed. Php obtains the textarea value and processes the carriage return and line feed method. the example in this article describes how php obtains the textarea value and processes the carriage return and line feed method. Let's share it with you for your reference. php obtains the textarea value and processes the carriage return line feed method. textarea returns the line feed.

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.


In PHP or HTML,After the content in MYSQL is entered, no line breaks will be output. Solution: Thank you </p>

There is an nl2br ($ string) function in PHP.
You need to use this function before entering the content into mysql.In the text box, convert the carriage return line break to
Symbol
The line feed is generated during the output.
We recommend that you do not have to worry about writing code when you are a beginner. Debug it by yourself. If you do not understand it, study it or Baidu ~ If you copy more data, you will get it.

How does php obtain the textarea value in a form?




</Form>

Do. php

$ Intext = $ _ POST ['text'];

Examples in this article describes how php obtains the textarea value and processes the carriage return and line feed. Share it with you for your reference...

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.