Einzelnen Beitrag anzeigen

StefanDP

Registriert seit: 11. Apr 2004
294 Beiträge
 
#4

Re: Funktion zur Textausgabe gesucht

  Alt 5. Jun 2004, 21:01
wenn ich das richtig verstehe möchtest du z.b. von
Code:
<html>
<body>
bla
hallo, wie gehts?</body>/html>
"bla hallo, wie gehts?" bekommen?

edit:
ich hab mal ne funktion gefunden und für eins meiner projekte erweitert:
Delphi-Quellcode:
function TAuswerten.PlainText(strHTML: string): string;
var
  P: PChar;
  InTag: Boolean;
begin
  // <head> löschen
  while (Pos('<head',strHTML) > 0) and
        (Pos('</head>',strHTML) > Pos('<head',strHTML)) do
    Delete(strHTML, Pos('<head',strHTML), (Pos('</head>',strHTML) + 7) - Pos('<head',strHTML));
  // <script> löschen
  while (Pos('<script',strHTML) > 0) and
        (Pos('</script>',strHTML) > Pos('<script',strHTML)) do
    Delete(strHTML, Pos('<script',strHTML), (Pos('</script>',strHTML) + 9) - Pos('<script',strHTML));
  // <style> löschen
  while (Pos('<style',strHTML) > 0) and
        (Pos('</style>',strHTML) > Pos('<style',strHTML)) do
    Delete(strHTML, Pos('<style',strHTML), (Pos('</style>',strHTML) + 8) - Pos('<style',strHTML));

// strHTML := StringReplace(strHTML,'
',' ',[rfReplaceAll]);
// Alle tags werden durch leerzeichen ersetzt
strHTML := StringReplace(strHTML,
'>','> ',[rfReplaceAll]);
P := PChar(strHTML);
Result :=
'';

InTag := False;
repeat
case P^ of
'<': InTag := True;
'>': InTag := False;
#13, #10: ; // nichts machen
else
if not InTag then
begin
if (P^ in [#9, #32]) and ((P+1)^ in [#10, #13, #32, #9,
'<']) then
else
Result := Result + P^;
end;
end;
Inc(P);
until (P^ = #0);

// HTML spezial umwandeln
Result := StringReplace(Result,
'&auml;', 'ä', [rfReplaceAll]);
Result := StringReplace(Result,
'&ouml;', 'ö', [rfReplaceAll]);
Result := StringReplace(Result,
'&uuml;', 'ü', [rfReplaceAll]);
Result := StringReplace(Result,
'&szlig;', 'ß', [rfReplaceAll]);
Result := StringReplace(Result,
'', ' ', [rfReplaceAll]);
Result := StringReplace(Result,
'*', ' ', [rfReplaceAll]);
Result := StringReplace(Result,
'>', '>', [rfReplaceAll]);
Result := StringReplace(Result,
'<', '<', [rfReplaceAll]);

{ Result := StringReplace(Result,
'&quot;', '"', [rfReplaceAll]);
Result := StringReplace(Result,
'&apos;', '''', [rfReplaceAll]);
Result := StringReplace(Result,
'&amp;', '&', [rfReplaceAll]);
}
end;
  Mit Zitat antworten Zitat