テキストエリアでEnterキーを押すと新しい行に移動しますが、テキストエリアが送信されたときにその新しい行は表示されません。どうすればこれを機能させることができますか? 簡単なはずですが、私が検索して試したところ、失敗しました。
<textarea style="{ white-space:pre; }"; name="texts" rows="3" cols="40"></textarea>
$texts = $_POST['texts'];
機能を探していると思いますnl2br()
。
おそらく問題は、改行が表示されていることですが、それをhtmlとして出力しているため、その改行が保存されていません。html として出力する場合、改行を区切りタグに変換する必要があります。次のように実行できます。
//editing per comment advice. Apparently this method shouldn't be used since it doesn't replace all possible newline representations, although I dont remember having an issue with it.
//$string = str_replace("\n", "<br />", $string);
//as others mentioned, this is better and easier:
$string = nl2br($string);
おそらく私は質問を誤解していますが、これは私がそれから得たものです。