<textarea style="resize: none;">
<?php
while ($row = mysql_fetch_array($result)) {
echo $row[1] . "\n";
}
?>
</textarea>
我想阻止最後一個值有一個換行符 - 我該怎麼做呢?我不想要底部的白色空間。如何防止上一次換行?
<textarea style="resize: none;">
<?php
while ($row = mysql_fetch_array($result)) {
echo $row[1] . "\n";
}
?>
</textarea>
我想阻止最後一個值有一個換行符 - 我該怎麼做呢?我不想要底部的白色空間。如何防止上一次換行?
<textarea style="resize: none;">
<?php
$rows = array();
while ($row = mysql_fetch_array($result)) {
$rows[] = $row[1];
}
echo implode($rows, "\n");
?>
</textarea>
我平時做這樣的事情:
<textarea style="resize: none;">
<?php
while ($row = mysql_fetch_array($result)) {
if($stuff==''){
$stuff=$row[1];
}else{
$stuff.= "\n" . $row[1];
}
}
print $stuff;
?>
</textarea>
<?php
$results = array();
while ($row = mysql_fetch_array($result))
$results[] = $row[1];
echo implode("\n", $results);
?>
或
<?php
$first = true;
while ($row = mysql_fetch_array($result)) {
if (!$first)
echo "\n";
echo $row[1];
$first = false;
}
?>
保存在一個變量,然後從該字符串的最後一個字符的行。
<?php
$content = '';
while ($row = mysql_fetch_array($result)) {
$content .= $row[1] . "\n";
}
echo substr($content, 0, strlen($content) - 1);
?>
這應該工作:
<?php
$string = '';
while ($row = mysql_fetch_array($result)) {
$string .= $row[1] . "\n";
}
?>
<textarea style="resize: none;">
<?php echo trim($string,"\n"); ?>
</textarea>
一個辦法是做這樣的:
<textarea style="resize: none;">
<?php
$prefix= '';
while ($row = mysql_fetch_array($result)) {
echo $prefix . $row[1];
if($prefix == ''){
$prefix = "\n";
}
?>
</textarea>
,似乎工作。像Python中的.join一樣運行。 –
僅供參考,'implode()'將參數置於任一位置,但爲了與'explode()'一致,首選訂單是$ glue,$ pieces' – hafichuk
+1。 :) – Herbert