PHP method to get the value of textarea and process carriage return and line feed, textarea carriage return and line feed_PHP tutorial
WBOY
Release: 2016-07-13 10:16:35
Original
1075 people have browsed it
php method to get the value of textarea and process carriage return and line feed, textarea carriage return and line feed
The example in this article describes how PHP obtains the value of textarea and handles carriage returns and line feeds. Share it with everyone for your reference. The specific implementation method is as follows:
Generally speaking, in the textarea in the HTML form, when we press enter and line feed, they are encoded by some ASCII or special characters. If the conversion is not performed, the output text will not be typeset.
It is very simple for PHP to get the value of textarea. Textarea carriage return behavior rn Let’s see an example
HTML code:
Copy code The code is as follows:
PHP code:
Copy 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); // Carriage return is replaced by line feed
echo $str1;
All codes:
Copy 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);//Default function for carriage return to line break
echo $str1;
?>
Let’s look at an example from the dz forum. Not much more to say, just go to the code:
Copy code The code is as follows:
$names = preg_split('/rn/',$_POST['textarea']);
foreach($names as $name){
// todo something eg: echo $name;
}
Getting the value is very simple, but as for the assignment, outputting the newline character in the textarea is not that simple
"
"and"
"What does it mean
I believe you have all seen it. In fact, the carriage return in the textarea becomes the character "n", so when php handles the carriage return in the textarea, it actually processes the "n" in the character.
I hope this article will be helpful to everyone’s PHP programming design.
In PHP or HTML, after the content in
There is a nl2br ($string) function in PHP Before inputting the content into mysql, you need to use this function to process the content in
How to get the value of textarea in the form in php?
do.php
$intext = $_POST['intext'];
http://www.bkjia.com/PHPjc/897014.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/897014.htmlTechArticlephp method to get the value of textarea and process carriage return and line feed, textarea carriage return and line feed. This article describes the example of php getting textarea The value and the method of handling carriage return and line feed. Share it with everyone for your reference...
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn