电贺 是否可以使用PHP为textarea的每一行添加后缀? 我知道我们可以从textarea获取文本到Variables然后呢?如何将enter-(换行)添加为变量?
答案 0 :(得分: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 = Difference between \n and \r?