Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
Ich will den Text aus der .txt-Datei laden, damit ich nicht immer den Text direkt in der HTML-Datei ändern muss.ja mit php.
Obwohl man txt datein eigentlich auch mit Javascript oder auch dein Iframe öffnen kann ( wenn txt datei auf Server liegt ).
Wenn man die mit Php oder Javascript öffnet kann man die auch auseinander nehmen und nur das anzeigen was man davon brauch.
Wie sieht den deine TXT Datei aus und was willst du davon anzeigen ?
<?php include('test.txt'); ?>
oder
<?php readfile('test.txt'); ?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>.txt in HTML einbinden</title>
<style>
#inhalt,body{
color:red;
font-family: 'Dosis';
}
</style>
<link href="https://fonts.googleapis.com/css?family=Dosis&display=swap" rel="stylesheet">
</head>
<body>
<h1 style="text-decoration: underline; color: rgb(36, 125, 160);">Überschift</h1>
<p1>Unter mir soll .txt-Datei <a href="Text.txt">Text.txt</a> , mit der Schriftart 'Dosis' eingebunden werden.</p1>
<div id="inhalt"></div>
<script>
window.onload = function () {
div=document.getElementById('inhalt');
var linksrc = "test.txt";
let xhr = new XMLHttpRequest ();
xhr.onreadystatechange = function () {
if (this.readyState === 4 && this.status === 200) {
let response = this.responseText;
div.innerHTML+=response;
div.style.color='red';
}
}
xhr.open ("GET", linksrc);
xhr.send ();
}
</script>
</body>
</html>
Funktioniert bei mir leider nicht.Kommt drauf an wie du es gerne hättest.
Du kannst iframe nehmen
oder object
http request ( ajax ).
Oder php mit file(), filer_get_contents() , readfile oder include();
Da gibt es wohl noch mehr möglichkeiten.
versuch es einfach mal mit include oder readfile, wäre jetzt am einfachsten.
Ansonsten JavascriptPHP:<?php include('test.txt'); ?> oder <?php readfile('test.txt'); ?>
Code:<!DOCTYPE html> <html lang="de"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>.txt in HTML einbinden</title> <style> #inhalt,body{ color:red; font-family: 'Dosis'; } </style> <link href="https://fonts.googleapis.com/css?family=Dosis&display=swap" rel="stylesheet"> </head> <body> <h1 style="text-decoration: underline; color: rgb(36, 125, 160);">Überschift</h1> <p1>Unter mir soll .txt-Datei <a href="Text.txt">Text.txt</a> , mit der Schriftart 'Dosis' eingebunden werden.</p1> <div id="inhalt"></div> <script> window.onload = function () { div=document.getElementById('inhalt'); var linksrc = "test.txt"; let xhr = new XMLHttpRequest (); xhr.onreadystatechange = function () { if (this.readyState === 4 && this.status === 200) { let response = this.responseText; div.innerHTML+=response; div.style.color='red'; } } xhr.open ("GET", linksrc); xhr.send (); } </script> </body> </html>
https://drive.google.com/open?id=1PI7Gz6A1g3wQSfhqSRBXYwHM4wmj053bWas geht den daran nicht ?
Was für Fehler werden den angezeigt ?
Geht der Php Code auch nicht ?
Kannst du das mal Online stellen damit man das mal sehen kann
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>.txt in HTML einbinden</title>
<style>
#inhalt,body{
color:red;
font-family: 'Dosis';
}
</style>
<link href="https://fonts.googleapis.com/css?family=Dosis&display=swap" rel="stylesheet">
</head>
<body>
<h1 style="text-decoration: underline; color: rgb(36, 125, 160);">Überschift</h1>
<p1>Unter mir soll .txt-Datei <a href="test.txt">Test.txt</a> , mit der Schriftart 'Dosis' eingebunden werden.</p1>
<div id="inhalt"></div>
<script>
window.onload = function () {
div=document.getElementById('inhalt');
var linksrc = "test.txt";
let xhr = new XMLHttpRequest ();
xhr.onreadystatechange = function () {
if (this.readyState === 4 && this.status === 200) {
let response = this.responseText;
div.innerHTML+=response;
div.style.color='red';
}
}
xhr.open ("GET", linksrc);
xhr.send ();
}
</script>
</body>
</html>
Ich wurde mit XMLHttpRequest eingebunden.
<h2>Hier mit php readfile() </h2>
<div id="inhalt2"><?php readfile('test.txt'); ?></div>
<p class="p1">
.