为每一行添加后缀 [PHP 和文本区域 HTML]

Adding suffix to every line [PHP and textarea HTML]

问候 是否可以使用 PHP 为 textarea 的每一行添加后缀? 我知道我们可以将文本从 textarea 获取到 Variables,然后呢?如何添加 enter-(新行)作为变量?

这个有效:

<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>";

?>

在此处阅读有关运输 return 和换行的更多信息:\r\n = Difference between \n and \r?