Ich habe eine Datei data.txt, die aus einer Textarea in eine HTML-Seite mit PHP schreibt.PHP Convert Neue Zeile in Textarea zu <BR>
Ich möchte der Textbereich neue Zeilen als <br>
Element lesen, so dass es nicht auf der gleichen Zeile ist, wenn ich eine neue Zeile erstellen.
Beispiel:
Hello
Hello
gleich
HelloHello
aber ich will es
Hello
Hello
ich bereits versucht haben, gleich n2lbr
Umsetzung, aber es ist schwer, mit meinem System zu implementieren, so Wenn Sie vorschlagen, dass zeigen Sie bitte wie.
SO hier ist mein Code:
HTML:
<form method="POST" action="process.php" onsubmit='return validate()' >
<textarea cols='60' rows='8' id="input1" type="text" name="myInputName" style="background:white;border:2px solid #dfdfdf;color:black;height:50px;"></textarea>
<input type="submit" name="submitButton" value="Post" style="width:60px;height:55px;background:white;color:black;border:2px solid #dfdfdf;" class="cbutton" />
</form>
<form method="POST" action="clear.php">
<input type="submit" name="Clear" value="Erase" style="width:265px;height:30px;background:white;color:black;border:2px solid #dfdfdf;margin-top:2px;" class="cbutton"/>
</form>
</div>
<p style="font-size:35px;text-align:center;font-family:Raleway;">To do List</p>
<div id="list2" style="">
<?php
$myfilename = "data.txt";
if (file_exists($myfilename)) {
echo file_get_contents($myfilename);
nl2br($myfilename);
}
?>
PHP (process.php):
<?php
// We will put the data into a file in the current directory called "data.txt"
// But first of all, we need to check if the user actually pushed submit
if (isset($_POST['submitButton'])) {
// The user clicked submit
// Put the contents of the text into the file
file_put_contents('./data.txt', $_POST['myInputName'] . '</br>', FILE_APPEND);
$str = $_POST["myInputName"] echo nl2br($str);
// ./data.txt: the text file in which the data will be stored
// $_POST['myInputName']: What the user put in the form field named "myInputName"
// FILE_APPEND: This tells the function to append to the file and not to overwrite it.
header('Location: index.php');
}
Vielen Dank im Voraus!
Habe eine Menge Probleme damit gehabt.
in Ihrem html Ihr Echo der Datei Inhalt außerhalb der Textarea - so wird es nie funktionieren. Sie wenden auch nl2br auf den Dateinamen an, nicht auf den Inhalt. –
können Sie nicht einfach 'echo nl2br (file_get_contents ($ myfilename))' '? – junkfoodjunkie
Ich werde jetzt versuchen. Ich habe alles versucht, woran ich denken kann, deshalb war es wahrscheinlich, dass ich außerhalb des Textfelds mit allem experimentierte, was mir einfiel. –