问候是否可以使用 PHP 为 textarea 中的每一行添加后缀?我知道我们可以将文本从 textarea 获取到变量,然后呢?如何添加 enter- (新行)作为变量?
问问题
163 次
1 回答
0
这有效:
<form method="GET">
<textarea name="inputFromTextArea">This is line 1
This is line 2
...
This is line 4</textarea>
<input type="submit">
</form>
<?php
/* Convert text with lines to an array (\r\n = Carriage return & Newline on Windows machines*/
$lines = explode("\n", $_GET['inputFromTextArea']);
/* debug information to show the contents of $lines */
echo "<pre>";
print_r($lines);
echo "</pre>";
/* Loop over all lines and manipulate each line */
foreach($lines as $lineNr => $line){
$lines[$lineNr] = trim($line,"\r") . " a suffix here "; // remove possible Carriage returns & concatenate stuff
}
/* debug information to show the contents of $lines */
echo "<pre>";
print_r($lines);
echo "</pre>";
?>
在此处阅读有关回车和换行符的更多信息:\r\n = \n 和 \r 之间的区别?
于 2017-02-21T13:50:38.913 回答