antinator
Goto Top

Zeilenumbruch ohne br

Ich habe einen <div> in den durch ein phpscript der Inhalt einer Textdatei eingegeben wird. Welcher wiederum aus einem textarea kommt (dadurch kann ich keine <br> nutzen, weil wenn jemand in dem textarea in die nächste Zeile gehen will, wird das in der Textdatei auch nur als neue Zeile eingetragen. Resultat: Wenn der Inhalt gezeigt wird, wird dies nicht wahrgenommen face-sad


index.php:
<div id="beides3" align="left" ><div style="style= margin-left:75px;margin-right:75px;width:830;">Kommentare:</div><br>  
<br><br> 
<div id="kommentar">  
    <style>
#komment
{
color:white;
background:#FF6600;
border:0px; margin-right:75px;
width:150px;
}
#komment:hover 
{
color:white;
background:#FF8533;
border:3px;
border-color:#FFB380;
}

    </style>
<form action="kommentar.php" method="post" name="form1">  
<textarea id="eingabe" onkeydown="setTimeout('addZeile(document.getElementById(\'eingabe\'))',10)" rows="2" class="commentthread_textarea" name="nachricht" cols='0' style="background:#FF944D; color:white; overflow: hidden; margin-left:75px; weight:680px; height: 20px;width:680px;" onkeydown="setTimeout('addZeile(document.getElementById(\'eingabe\'))',10);" placeholder="Einen Kommentar hinzufügen"></textarea><input class="komment" id="komment"class="button" type="submit" name="komment" value="Kommentar verfassen" >  
</form>
</div>
<div id="kommentare">  
<?php {readfile('./chat.txt'); } ?>  
</div>
</div>
Entschuldigung für diese unübersichtliche schreibweise :/

kommentar.php
<?php
session_start();
$nachricht = $_POST["nachricht"];  
$user = $_SESSION['user'];  
if( $nachricht == "" ){  

echo "<script language=\"JavaScript\">  
<!--
 alert(\"Bitte gib erstmal einen Inhalt an!\"); 
//-->
</script>
";    
  include("index.php");  

}else{

$datei = "chat.txt";   
$datum = date("j F Y");  
$uhrzeit = date("H:i");  
$text1 = '<div id="topkom"><a href="../../../system/User/'.$user.'/">'.$user.'</a>&nbsp;&nbsp;&nbsp;<div id="topkomdate">'.$datum.' um '.$uhrzeit.' Uhr</div></div><div id="topkommessage"><br>';  
$text2 = $nachricht.'</div><br>  
<br>';  
$textdatei = fopen ($datei, "a+");   
fwrite($textdatei, $text1);
fwrite($textdatei, $text2);
fclose($textdatei);
echo "<script language=\"JavaScript\">  
<!--
 alert(\"Nachricht erfolgreich abgesendet!\"); 
//-->
</script>
";    
  include("index.php");  
}
?>


Habt ihr irgendwelche Lösungen für mein Problem?face-smile Das ganze soll halt wie das steamprofikommentarsystem sein und es funktioniert ja auch es seiden jemand schreibt eine Nachricht, die über den Rand geht oder einen Zeilenumbruch beinhält.

Content-Key: 287807

Url: https://administrator.de/contentid/287807

Printed on: April 19, 2024 at 12:04 o'clock

Mitglied: 122990
122990 Nov 08, 2015 updated at 09:34:04 (UTC)
Goto Top
Moin,
#komment
immer dieses "Denglisch", oh "komment" der Herr und segne euch face-big-smile

packe den Text einfach in ein <pre> </pre> Tag ...

PRE für "Preformated"

Gruß grexit
Member: zuffen
zuffen Nov 08, 2015 at 10:32:47 (UTC)
Goto Top
dein entscheidender fehler ist, nicht zu wissen, das der zeilenvorschub in einer datei Nicht mit dem HTML-Tag <br> gemacht wird. dort wird das CHAR (13) verwendet.

du musst den string aus der datei vor dem senden replacen.
so z. b. echo str_replace ( LF, br,
file_get_contents ( $GLOBALS [ "filename" ] )
) ;

dasz du ein verfechter der abm ( arbeitsbeschaffungsmassnahme) bist, ergibt dein source.

ich bevorzuge bei php die alternative schreibweise, ( u.a. manche texteditoren machen keine hightlights).

so koennte einigermassen formatiert dein text aussehen.

<?php

$GLOBALS [ "filename" ] = dirname ( __FILE__ ) . '/chat.txt';
define ( "LF", "\n" );
define ( "br", "&lt;br>" );
if ( isset ( $_POST [ "komment" ] ) ):
kommentar ();
endif;

?>
&lt;style>

#komment {
color:white;
background:#FF6600;
border:0px;
width:150px;
}


&lt;/style>


&lt;div id="beides3"
align="left" >
&lt;div
style="
margin-right:75px;
width:830;"
>
Kommentare:
&lt;/div>

&lt;br>

&lt;div id="kommentar">

&lt;form action = "" method = "post" name = "form1">

&lt;textarea id="eingabe"
rows="5"
name="nachricht"
cols='0'
style=" background:#FF944D;
color: white;
height: 80px;
width: 680px;
border: 3px solid black;
placeholder="Einen Kommentar hinzufügen">
&lt;/textarea>

&lt;br>

&lt;input class="komment"
id="komment"class="button"
type="submit"
name="komment"
value="Kommentar verfassen"
>

&lt;/form>

&lt;/div>

&lt;div id="kommentare">

&lt;?php kommentar_text (); ?>


&lt;/div>

&lt;/div>


&lt;?php

FUNCTION kommentar_text () {

if ( !file_exists ( $GLOBALS [ "filename" ] ) ):
file_put_contents ( $GLOBALS [ "filename" ],
"Der erste " . LF );
endif;

echo str_replace ( LF, br,
file_get_contents ( $GLOBALS [ "filename" ] )
) ;

}


FUNCTION kommentar () {

session_start();
$nachricht = $_POST["nachricht"];
unset ( $_POST [ "komment" ] );
$user = "user: ??????";

;
if ( !kommentar_mit_inhalt ( $nachricht ) ):
return;
endif;

$datei = "chat.txt";
$datum = date("j F Y");
$uhrzeit = date("H:i");
$text1 = '&lt;div id="topkom">
&lt;a href="../../../system/User/'
. $user
.
'/">'
. $user
. '&lt;/a>&nbsp;&nbsp;&nbsp;'
. '&lt;div id="topkomdate">'
. $datum
. ' um '
. $uhrzeit
. ' Uhr&lt;/div>&lt;/div>&lt;div id="topkommessage">&lt;br>';
$text2 = $nachricht
. '&lt;/div>';


file_put_contents ( $GLOBALS [ "filename" ],
$text1 . LF
. $text2 . LF
. file_get_contents
( $GLOBALS [ "filename" ] ) );

}


FUNCTION kommentar_mit_inhalt ( $nachricht ) {

if ( trim ( $nachricht ) == "" ):
echo "&lt;script language=\"JavaScript\">
&lt;!--
alert(\"Bitte gib erstmal einen Inhalt an!\");
//-->
&lt;/script>
";
return false;
endif;

return true;

}