• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

Auslesen einer HTMLDatei in Textarea

JBExtrem

Neues Mitglied
Hallo,

ich programmiere derzeit ein eigenen Blog und möchte einen HTML Datei in eine Textarea einlesen. Hier mein Code:
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<title>TinyMCE Test</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>

<!-- OF COURSE YOU NEED TO ADAPT NEXT LINE TO YOUR tiny_mce.js PATH -->
<script type="text/javascript" src="tinymce/jscripts/tiny_mce/tiny_mce.js"></script>

<script type="text/javascript">
tinyMCE.init({
        mode : "textareas",
        theme : "advanced",
        plugins : "emotions,spellchecker,advhr,insertdatetime,preview", 
                
        // Theme options - button# indicated the row# only
        theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,|,justifyleft,justifycenter,justifyright,fontselect,fontsizeselect,formatselect",
        theme_advanced_buttons2 : "cut,copy,paste,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,image,|,code,preview,|,forecolor,backcolor",
        theme_advanced_buttons3 : "insertdate,inserttime,|,spellchecker,advhr,,removeformat,|,sub,sup,|,charmap,emotions",      
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true
});
</script>
</head>

<body>
<?php
// 
$text = file_get_contents("news.html");
echo $text; // Dateiinhalt ausgeben
?>


        <p>     
                <form action="text_edit.php" name="edit_file" method="post">
            <textarea name="text"> </textarea>
                <input type="submit" value="Abspeichern" />
        </p>
</form>

</body>
</html>

Ich hoffe ihr könnt mir helfen und danke im vorrraus

MfG

Julian
 
Hallo Julian,
probier es mal damit (ab Anfang des <body> tags abwärts):
Code:
$handle = fopen("news.html", "r");
$content = fread($handle, filesize("news.html"));
fclose($handle);


<body>
<?php
$handle = fopen("news.html", "r");
$content = fread($handle, filesize("news.html"));
?>


        <p>     
                <form action="text_edit.php" name="edit_file" method="post">
					<?php echo '<textarea name="text">'.$content.'</textarea>'; fclose($handle); ?>
                <input type="submit" value="Abspeichern" />
        </p>
</form>

</body>
</html>
Mit freundlichen Grüßen
 
Kannst du mir das vllt. in einer fertigen PHP Datei machen Namens edit.php ich verstehe das irgendwie nicht
 
Wieso so kompliziert? Da finde ich den Versuch von JBExtrem besser.

Die Funktion file_get_contents liefert einen String zurück, diesen einfach gleich zwischen <textarea> und </textarea> ausgeben.
PHP:
<body>         
<p>                      
<form action="text_edit.php" name="edit_file" method="post">             
<textarea name="text"><?php echo file_get_contents("news.html"); ?></textarea>                 
<input type="submit" value="Abspeichern" />        
</p> 
</form>  
</body>
 
Da bekomme ich eine blanke Seite mit deinem Code T!P-TOP! Nur als Hinweiß ich habe da TinyMCE drauf
 
Hallo Julian,
Der Code von T!P-TOP war auch nur der Inhalt des <body>.
Der komplette Code sollte so aussehen:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<title>TinyMCE Test</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>

<!-- OF COURSE YOU NEED TO ADAPT NEXT LINE TO YOUR tiny_mce.js PATH -->
<script type="text/javascript" src="tinymce/jscripts/tiny_mce/tiny_mce.js"></script>

<script type="text/javascript">
tinyMCE.init({
        mode : "textareas",
        theme : "advanced",
        plugins : "emotions,spellchecker,advhr,insertdatetime,preview", 
                
        // Theme options - button# indicated the row# only
        theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,|,justifyleft,justifycenter,justifyright,fontselect,fontsizeselect,formatselect",
        theme_advanced_buttons2 : "cut,copy,paste,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,image,|,code,preview,|,forecolor,backcolor",
        theme_advanced_buttons3 : "insertdate,inserttime,|,spellchecker,advhr,,removeformat,|,sub,sup,|,charmap,emotions",      
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true
});
</script>
</head>
<body>         
<p>                      
<form action="text_edit.php" name="edit_file" method="post">             
<textarea name="text"><?php echo file_get_contents("news.html"); ?></textarea>                 
<input type="submit" value="Abspeichern" />        
</p> 
</form>  
</body>
</html>
Mit freundlichen Grüßen
 
Wo hast du TinyMCE drauf?

Versuchs mal so:
PHP:
<body>         
<p>                      
<form action="text_edit.php" name="edit_file" method="post">             
<textarea name="text">
<?php 
$content = file_get_contents("news.html"); 
echo $content;
?>
</textarea>                 
<input type="submit" value="Abspeichern" />        
</p> 
</form>  
</body>
 
Aber er ließt trotzdem kein Inhalt aus der Datei
Dann machst Du was falsch.
Sicher, dass du den richtigen Pfad hast? Befindet sich news.html im selber Verzeichnis wie das Script, wo Du versuchst, den Inhalt der Datei auszulesen?

//PS: setzte mal error reporting(E ALL) an den Anfang deiner Seite.
 
Zurück
Oben