Hilfe für Parser gesucht

froggiton

Grünschnabel
Hallo,

ich bin ein PHP neuling und suche jemanden, der mit mir einen Parser für html seiten programmiert oder mir dabei hilft.


Meine Vorstellungen:
Ich gebe in einem Formular eine Url ein, dann soll der komplette Quellcode verändert
und auf meinem Webspace gespeichert werden.


Ich habe nun schon seit Stunden diverse PHP seiten durchgesehen, doch
leider alles ohne wirklichen erfolg!
Bei meinem bisher besten ansatz, konnte ich den Quellcode Auslesen und Speichern.
Eine kleine veränderung habe ich sogar auch hinbekommen, leider reicht das aber nicht.
In der Datei kommen mehrere Koordinaten vor, die ich ersetzen muss. Desweiteren sind in der Datei weitere Daten, (wie z.b. Usernamen) die ich in der Neuen Datei (z.b. im Dateinamen) verwenden möchte.
PHP:
<?PHP
$lines=file("http://www.eineseite.de/ordner/datei.htm");
$file=fopen("neuedatei.htm","w");
for ($i=0;$i<count($lines);$i++)
{
$ersatz="";
$lines[$i]=ereg_replace("Planet", $ersatz, $lines[$i]);
fputs($file,$lines[$i]);
}
fclose($file);
?>
Und nun komme ich einfach nicht weiter und bitte euch mir zu helfen.


Gruß froggiton
 
Zuletzt bearbeitet:
Ich habe keine Ahnung, wie ich jetzt Textpassagen suchen und ersetzen kann oder sie dann in eine Varriable zu Speichern um sie weiter zu verwenden.

z.b. alle Koordinaten sollen unkenntlich gemacht werden. eine Koordinate hat immer diesen aufbau:
17x316x7 od. 1x22x12 od 2x4x9
soll dann aber so aussehen:
--x---x--

Code:
 <td align="left"><br>Bericht &uuml;ber den <b>Kampf</b> auf	<b>2x447x6 von [ZAw] Skot</b>
<br>Zeit <b>24.05. 17:56 Uhr</b><br></center><br><table border="0" cellspacing="0" cellpadding="0" width="665px">
Dann brauche ich den Benutzernamen in einer Varriable, weil aus beiden namen, der neue Name der Datei entstehen soll. Dann noch Datum und Uhrzeit.

Nach dem Speichern der Datei soll der Dateiname noch in eine MySQL Tabelle Gespeichert werden.
 
Unter einem Parser verstehe ich aber etwas anderes:
Ein Parser […] ist ein Programm, das entscheidet, ob eine Eingabe zur Sprache einer bestimmten Grammatik gehört. Er benutzt dabei in der Regel einen separaten Scanner (auch Lexer genannt), um eine zeichenweise vorliegende Eingabe vorher in Token […] zu konvertieren.

Bei deinem Problem solltest du am besten mit regulären Ausdrücken arbeiten. Zum Ersetzen der Koordinaten wäre beispielweise folgendes möglich:
PHP:
<?php

	…
	$string = preg_replace('/[0-9]+x[0-9]+x[0-9]+/', '--x--x--', $string);
	…

?>
 
Danke das Funktioniert schon mal...

Aber wie bekomme ich nun die Usernamen in 2 Varriablen hinein?
$angreifer
$verteidiger

Code:
 <td height="35px" bgcolor="#1A1A1A">
				 &nbsp;<font color="#CCCCCC">Startbasis<b> XZW-276 --x--x--</b><br>&nbsp;von [-ikj-] Skuriun&nbsp;
				</td>
				<td bgcolor="#1A1A1A" align="right">
				 &nbsp;<font color="#CCCCCC">Zielbasis<b> --x--x--</b>&nbsp;<br> von [ZAg]Skart&nbsp;
				</td>
 
Probier mal Folgendes:
PHP:
<?php

	…
	preg_match_all('/von ([\x20-\x7F]+)&nbsp;/', $string, $matches);
	$matches = $matches[1];
	print_r($matches);
	…

?>
Es wär übrigens einfacher, wenn du semantisches Markup benutzen würdest.
 
hmmm ich bekomme diese ausgabe:
Es sind zwar auch die Namen richtig enthalten ( Array ( [0] => [sg] VanRyun ) und Array ( [0] => [-pm-] eschi ) ), aber wie Kann ich die von da nun in eine Varriable legen?
Code:
Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( [0] => [sg] VanRyun ) Array ( ) Array ( ) Array ( [0] => [-pm-] eschi ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( )

Ich habe den Code so eingebaut, ist das Richtig?
PHP:
<?PHP
$lines=file("datei.txt");
$file=fopen("datei.htm","w");
for ($i=0;$i<count($lines);$i++)
{
$lines[$i] = preg_replace('/[0-9]+x[0-9]+x[0-9]+/', '--x--x--', $lines[$i]);
preg_match_all('/von ([\x20-\x7F]+)&nbsp;/', $lines[$i], $matches); 
	$matches = $matches[1]; 
	print_r($matches); 
fputs($file,$lines[$i]);
}
fclose($file);
?>
Es wär übrigens einfacher, wenn du semantisches Markup benutzen würdest.
Was ist das?
 
Probier mal Folgendes:
PHP:
<?php

	$data = file_get_contents('datei.txt');
	$data = preg_replace('/[0-9]+x[0-9]+x[0-9]+/', '--x--x--', $data);
	if( preg_match_all('/von ([\x20-\x7F]+)&nbsp;/', $data, $matches) ) {
		$matches = $matches[1];
		print_r($matches);
	}
	file_put_contents('datei.htm', $data);

?>
Google: Was ist semantisches Markup?
 
Das Funktioniert schon sehr gut so.
PHP:
 <?php 
	$data = file_get_contents('datei.txt'); 
	$data = preg_replace('/[0-9]+x[0-9]+x[0-9]+/', '--x--x--', $data); 
	if( preg_match_all('/von ([\x20-\x7F]+)&nbsp;/', $data, $matches) ) { 
		$matches = $matches[1]; 
		print_r($matches); 
	} 
	$matches = preg_replace('/[\[+\]]/', '_', $matches); 
	$name = "kb_am_datum_um_uhrzeit_$matches[0]_-vs-$matches[1].htm";
	file_put_contents($name, $data); 
 
?>

Jetzt brauche ich noch das Datum (&datum) und die Uhrzeit ($zeit)
Code:
<tr>
<td align="left"><br>Bericht &uuml;ber den <b>Kampf</b> auf Planet <b>11x119x15 Quadrupol von [-pm-] eschi</b>
<br>Zeit <b>25.05. 09:49 Uhr</b><br></center><br><table border="0" cellspacing="0" cellpadding="0" width="665px">
			 <tr>

und die Kampfwerte ($attangreifer, $deffangreifer, $attverteidiger, $deffverteidiger)
Code:
 <tr>
<td bgcolor="#2A2A2A" height="35px" >&nbsp;Gesamt<br>&nbsp;(netto)</td>
<td bgcolor="#2A2A2A" align="right"><font color="CCCCCC">13.460&nbsp;<br>11.224&nbsp;</td>
<td bgcolor="#2A2A2A"><font color="#888888">Att</font><br><font color="#888888">Def</font></td>
<td bgcolor="#2A2A2A"><font color="#CC5500">&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;<br></td>
<td bgcolor="#2A2A2A" align="right"><b>100%&nbsp;&nbsp;<br>100%&nbsp;&nbsp;</td>
<td>
</td>
<td bgcolor="#2A2A2A" align="right"><b>0%&nbsp;&nbsp;<br>0%&nbsp;&nbsp;</td>
<td bgcolor="#2A2A2A" align="right"><font color="#CC5500">&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;<br></td>
<td bgcolor="#2A2A2A" align="right"><font color="CCCCCC">0&nbsp;<br>0&nbsp;</td>
<td bgcolor="#2A2A2A" ><font color="#888888">Att</font><br><font color="#888888">Def</font></td>
<td bgcolor="#2A2A2A" align="right">Gesamt&nbsp;<br>(netto)&nbsp;</td>
</tr>

Kannst du mir da bitte auch noch helfen?
 
Zuletzt bearbeitet:
Zurück