HTML Seiten auslesen und in Datenbank schreiben
Code: Alles auswählen
while( list( $id, $text) = each( $array) )
{
$text = stripslashes($text);
if( !empty($text) or $text = " " )
{
// Ausführen wenn Zeile nicht leer ist
}
}
Zeile für Zeile.
Oder so wie Dennis geschrieben hat würds auch gehen.
Derzeitiger Stand (Problem besteht immer noch):
Code: Alles auswählen
<?php
$datei = "dateiname.htm";
$text = file($datei);
for ($i = 0; $i < count($text); $i++)
{
if( empty($text[$i]) || $text[$i] == " " || $text[$i] == "" || $text[$i] == " /n" || $text[$i] == "/n")
{
unset($text[$i]);
}
else
{
$text[$i] = preg_replace("/\<(.*?)\>/si", "", $text[$i]);
$text[$i] = str_replace(" ", "", $text[$i]);
$text[$i] = str_replace("<!--", "", $text[$i]);
$text[$i] = str_replace("var thispagename = self.location.href.substring(self.location.href.lastIndexOf('/')+1,self.location.href.length);", "", $text[$i]);
$text[$i] = str_replace("if(!parent.mainFrame)", "", $text[$i]);
$text[$i] = str_replace("{", "", $text[$i]);
$text[$i] = str_replace("}", "", $text[$i]);
$text[$i] = str_replace('window.location.href="index.html?"+thispagename;', "", $text[$i]);
$text[$i] = str_replace("//-->", "", $text[$i]);
$text[$i] = trim($text[$i]);
}
}
print_r($text);
?>
meine Foren: http://www.maxrev.de/communities.htm
Ich kaufe Dein Forum! Angebote bitte an marc at gutt punkt it
Ich kaufe Dein Forum! Angebote bitte an marc at gutt punkt it
- S2B
- Ehemaliges Teammitglied
- Beiträge: 3258
- Registriert: 10.08.2004 22:48
- Wohnort: Aachen
- Kontaktdaten:
Warum liest du die Datei eigentlich nicht mit fread() in einen String und bearbeitest den dann mit RegEx's oder str_replace()? Dann sparst du dir nämlich die ganzen Schleifen und hast auch kein Problem mehr mit trim()...
Gruß, S2B
Keinen Support per ICQ/PM!
Hier kann man meine PHP-Skripte und meine MODs für phpBB runterladen.
Keinen Support per ICQ/PM!
Hier kann man meine PHP-Skripte und meine MODs für phpBB runterladen.
ich brauche einen array, da die zeile x der titel ist und der text nachher die zeile y. (als beispiel) und die werte kommen dann nachher in die datenbank
ich verstehe das nicht.
warum gibt das:
plötzlich das aus:
bis einschließlich 35 schien es ja geklappt zu haben.. danach greift der filter aber nicht mehr und gibt den normalen inhalt aus?!
zeile 35 beinhaltet das:
ich verstehe das nicht.
warum gibt das:
Code: Alles auswählen
<?php
$datei = "dateiname.htm";
$text = file($datei);
for ($i = 0; $i < count($text); $i++)
{
$text[$i] = preg_replace("/\<(.*?)\>/si", "", $text[$i]);
$text[$i] = str_replace(" ", "", $text[$i]);
$text[$i] = str_replace("<!--", "", $text[$i]);
$text[$i] = str_replace("var thispagename = self.location.href.substring(self.location.href.lastIndexOf('/')+1,self.location.href.length);", "", $text[$i]);
$text[$i] = str_replace("if(!parent.mainFrame)", "", $text[$i]);
$text[$i] = str_replace("{", "", $text[$i]);
$text[$i] = str_replace("}", "", $text[$i]);
$text[$i] = str_replace('window.location.href="index.html?"+thispagename;', "", $text[$i]);
$text[$i] = str_replace("//-->", "", $text[$i]);
$text[$i] = trim($text[$i]);
if ( empty($text[$i]) || $text[$i] == " " || $text[$i] == "" || $text[$i] == " /n" || $text[$i] == "/n")
{
unset($text[$i]);
}
}
print_r($text);
?>
Code: Alles auswählen
Array
(
[36] => </tr>
[37] => <tr>
[38] => <td width="9%"> <div align="left"></div></td>
[39] => <td width="82%"> <div align="center">
[40] => <p><strong>titel</strong></p>
[41] => </div></td>
[42] => <td width="9%"> </td>
[43] => </tr>
[44] => <tr>
[45] => <td height="30"> </td>
[46] => <td height="30"> </td>
[47] => <td height="30"> </td>
[48] => </tr>
[49] => <tr>
[50] => <td height="30"> </td>
[51] => <td><div align="center">
[52] => <p>textzeile
[53] => textzeile
[54] => textzeile
[55] => textzeile
[56] => textzeile
[57] => textzeile
[58] => textzeile</p>
[59] => </div></td>
[60] => <td height="30"> </td>
[61] => </tr>
[62] => <tr>
[63] => <td width="9%" height="30"> </td>
[64] => <td width="82%" height="30"> <div align="right"><font face="Arial, Helvetica, sans-serif"><a href="lexikon.htm">zurück</a></font></div></td>
[65] => <td width="9%" height="30"> </td>
[66] => </tr>
[67] => </table>
[68] => </div>
[69] => </body>
[70] => </html>
)
zeile 35 beinhaltet das:
Code: Alles auswählen
<td colspan="3"> </td>
meine Foren: http://www.maxrev.de/communities.htm
Ich kaufe Dein Forum! Angebote bitte an marc at gutt punkt it
Ich kaufe Dein Forum! Angebote bitte an marc at gutt punkt it
Ok, der Fehler war naheliegend. Bei For-Schleifen wird der 2. Ausdruck in der Klammer immer wieder aufs neue geprüft und durch das Löschen einzelnder Array Elemente hat sich die Anzahl der Zeilen reduziert, was einen Abbruch der Schleife zur Folge hatte, bevor das Letzte eigentlich erreicht wurde.
Daher muss ich die Zeilenanzahl einfach vorher einmal zählen, bevor ich mit der Schleife beginne.
So sieht es jetzt aus:
am ende sortiere ich mit array_values die array ids neu und alles ist so wie es soll 
Daher muss ich die Zeilenanzahl einfach vorher einmal zählen, bevor ich mit der Schleife beginne.
So sieht es jetzt aus:
Code: Alles auswählen
<?php
$datei = "dateiname.htm";
$text = file($datei);
$textzeilen = count($text);
for ($i = 0; $i < $textzeilen; $i++)
{
$text[$i] = preg_replace("/\<(.*?)\>/si", "", $text[$i]);
$text[$i] = str_replace(" ", "", $text[$i]);
$text[$i] = str_replace("<!--", "", $text[$i]);
$text[$i] = str_replace("var thispagename = self.location.href.substring(self.location.href.lastIndexOf('/')+1,self.location.href.length);", "", $text[$i]);
$text[$i] = str_replace("if(!parent.mainFrame)", "", $text[$i]);
$text[$i] = str_replace("{", "", $text[$i]);
$text[$i] = str_replace("}", "", $text[$i]);
$text[$i] = str_replace('window.location.href="index.html?"+thispagename;', "", $text[$i]);
$text[$i] = str_replace("//-->", "", $text[$i]);
$text[$i] = trim($text[$i]);
if ( empty($text[$i]) )
{
unset($text[$i]);
}
}
$text = array_values($text);
print_r($text);
?>

meine Foren: http://www.maxrev.de/communities.htm
Ich kaufe Dein Forum! Angebote bitte an marc at gutt punkt it
Ich kaufe Dein Forum! Angebote bitte an marc at gutt punkt it
Code: Alles auswählen
<?php
$aktuell = getcwd();
$verzeichnis = opendir($aktuell);
while ($eintrag = readdir())
{
if (is_file($eintrag) && strrchr($eintrag, ".") == '.htm' )
{
$text = file($eintrag);
$textzeilen = count($text);
for ($i = 0; $i < $textzeilen; $i++)
{
$text[$i] = str_replace(">zurück<", "><", $text[$i]); // Diverse Filter für Tags, Zeilen und Wörter, die wir nicht gebrauchen können.
$text[$i] = preg_replace("/\<(.*?)\>/si", "", $text[$i]);
$text[$i] = str_replace(" ", "", $text[$i]);
$text[$i] = str_replace("<!--", "", $text[$i]);
$text[$i] = str_replace("var thispagename = self.location.href.substring(self.location.href.lastIndexOf('/')+1,self.location.href.length);", "", $text[$i]);
$text[$i] = str_replace("if(!parent.mainFrame)", "", $text[$i]);
$text[$i] = str_replace("{", "", $text[$i]);
$text[$i] = str_replace("}", "", $text[$i]);
$text[$i] = str_replace('window.location.href="index.html?"+thispagename;', "", $text[$i]);
$text[$i] = str_replace("//-->", "", $text[$i]);
$text[$i] = trim($text[$i]);
if ( empty($text[$i]) )
{
unset($text[$i]);
}
}
$text = array_values($text);
$titel = addslashes($text[0]);
$beschreibung = addslashes(trim(str_replace($titel, '', implode(" ", $text))));
if ( !empty($titel) && !empty($beschreibung) && strpos($titel, 'Adobe Web-Fotogalerie') === false ) // Hier werden die Dateien gefiltert, die nicht zum Lexikon hinzugefügt werden sollen. Am besten vor dem SQL erst alle Titel und Beschreibungen per Echo ausgeben
{
$sql = "INSERT INTO ". LEXIKON ." (titel,text) VALUES ('$titel','$beschreibung')";
if ( !mysql_query($sql) )
{
die("Message: Could not update lexikon information <br> at File: " . __FILE__ . " on line: " . __LINE__);
}
}
}
}
closedir($verzeichnis);
?>
meine Foren: http://www.maxrev.de/communities.htm
Ich kaufe Dein Forum! Angebote bitte an marc at gutt punkt it
Ich kaufe Dein Forum! Angebote bitte an marc at gutt punkt it
ersetz mal das:
gegen das um zu schauen was überhaupt für inhalte da sind:
Code: Alles auswählen
$titel = addslashes($text[0]);
$beschreibung = addslashes(trim(str_replace($titel, '', implode(" ", $text))));
if ( !empty($titel) && !empty($beschreibung) && strpos($titel, 'Adobe Web-Fotogalerie') === false ) // Hier werden die Dateien gefiltert, die nicht zum Lexikon hinzugefügt werden sollen. Am besten vor dem SQL erst alle Titel und Beschreibungen per Echo ausgeben
{
$sql = "INSERT INTO ". LEXIKON ." (titel,text) VALUES ('$titel','$beschreibung')";
if ( !mysql_query($sql) )
{
die("Message: Could not update lexikon information <br> at File: " . __FILE__ . " on line: " . __LINE__);
}
}
Code: Alles auswählen
print_r($text);
meine Foren: http://www.maxrev.de/communities.htm
Ich kaufe Dein Forum! Angebote bitte an marc at gutt punkt it
Ich kaufe Dein Forum! Angebote bitte an marc at gutt punkt it