PHP gets the value of textarea and handles the method of carriage return line, textarea carriage return _php tutorial

Source: Internet
Author: User

PHP gets the value of textarea and handles the method of carriage return, textarea carriage return line


This example describes how PHP gets the value of the textarea and handles the carriage return line-wrapping method. Share to everyone for your reference. The implementation method is as follows:

In general, in the HTML form textarea we press Enter and line wrapping are some ASCII or special character encoding, if not to convert the output text is not typesetting.

PHP gets textarea value is very simple textarea carriage return behavior \ r \ n See example below
HTML code:

Copy the Code code as follows:
PHP Code:

Copy the Code code as follows: $str =$_get[' Test '];
echo $str. '
';
$arr =explode ("\ n", $str);
Print_r ($arr);
echo Count ($arr). '
';//Carriage return number
$str 1=nl2br ($STR);//carriage return for newline
echo $str 1;
All code:

Copy the Code code as follows:





<?php
$str =$_get[' test '];
echo $str. '
';
$arr =explode ("\ n", $str);
Print_r ($arr);
echo Count ($arr). '
';//Carriage return number
$str 1=nl2br ($STR);//carriage return to a newline default function
echo $str 1;
?>


Take another look at the DZ Forum example. Not much to say, directly on the code:

Copy the code as follows: $names = Preg_split ('/\r\n/', $_post[' textarea ']);
foreach ($names as $name) {
Todo something Eg:echo $name;
}
The value is very simple, so assignment, output line break in textarea is not that simple

Copy the Code code as follows: $vals = Get_from_mydb ();
$tmp = ";
foreach ($vals as $val) {
$tmp. = $val. ";
}
"and" "What does that mean?"
I believe we all see, in fact, textarea in the carriage return into a character is "\ n", so the PHP processing textarea in the carriage is actually processing characters in the "\ n".

I hope this article is helpful to everyone's PHP programming.


PHP or HTML, the content into MySQL and then output there is no line-wrapping solution humbly </p></span>

There is a nl2br ($string) function in PHP
You need to use this function to process the contents of the content before entering MySQL , and convert the carriage return line character into the HTML markup language.
Symbol
The output will be replaced by a line.
It is recommended that you do not have to hurry to write code, first copy the code. I have to play the debugging. Encounter do not understand the study, or Baidu ~ Copy more will be

How does PHP get the TEXTAREA value in the form?



</form>

do.php

"!--? php
$intext = $_post[' intext '];
 

http://www.bkjia.com/phpjc/897014.html www.bkjia.com True http://www.bkjia.com/phpjc/897014.html techarticle PHP gets the value of textarea and handles the method of carriage return line, textarea carriage return line This article describes how PHP gets the value of textarea and handles the carriage return line break method. Share to everyone 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.