文本区域空白

php*_*eak 1 html php whitespace textarea

每次我更新表单文本区域时,表单都会添加一个空格。这是一个问题,因为我使用文本区域输入为用户使用的每个新行创建一个新的数组元素。

HTML:

<textarea class='form-control input-lg' name='stout' style='width:100%;min-height:200px;resize: none; '> 
     <?php $a = $functie-  >_getFileContent('../content/stout.txt', 'j');
     echo $bewerking->_extraInfoInput($a);?>
</textarea>
Run Code Online (Sandbox Code Playgroud)

功能:

public function _extraInfoInput($a){
    $a = preg_replace('/ /', '', $a);

    return $a;
}

 public function _getFileContent($file,$uitzondering){       
   $content = file_get_contents($file);        
   if($content != ''){
       if($uitzondering == ''){
           $a = $content.'<br/>';
       }
       else{

           $a = $content;

       }
       return $a;
   }  
Run Code Online (Sandbox Code Playgroud)

}

Chr*_*ear 5

你的 html 中有空格。改成这样

<textarea class='form-control input-lg' name='stout' style='width:100%;min-height:200px;resize: none;'><!-- no whitespace here--><?php $a = $functie-  >_getFileContent('../content/stout.txt', 'j');
 echo $bewerking->_extraInfoInput($a);?><!-- or here --></textarea>
Run Code Online (Sandbox Code Playgroud)