2014-01-27 35 views
2

每次我提交textarea時,它都會自動在textarea框的頂部添加行間距。如何以及在何處添加僅使用返回鍵輸入新行的編碼?如何使用PHP添加和刪除行距?

<div class="header"> 
<form enctype="multipart/form-data" action="mycomments.php" method="POST"> 
<textarea input type="text" name="Comments" style="height:100%;width:100%" 
cols="100%" rows="10" ><?php include 'comments.php';?></textarea> 
<br> 
<input type="submit" value="Submit"> 
</form> 
</div> 
+4

你看過'comments.php'中的內容嗎?只是因爲這個特定的代碼片段沒有額外的換行符,並不意味着你所包含的文件也不會... –

回答

0

不知道究竟是什麼的推移裏面comments.php,你必須這樣做:

<?php 
ob_start(); 
include 'comments.php'; 
$buffer = trim(ob_get_clean()); 
?> 
<textarea input type="text" name="Comments" style="height:100%;width:100%" 
cols="100%" rows="10" ><?php echo htmlspecialchars($buffer); ?></textarea> 

裝飾()函數擺脫從一開始就和字符串的結束空白。

+0

謝謝,這工作。 – user2714558

+0

@ user2714558太棒了!您是否介意點擊答案旁邊的綠色複選標記以將其標記爲已接受? –