Autor Beitrag
Coder
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1383
Erhaltene Danke: 1

WinXP
D2005 PE
BeitragVerfasst: Do 13.04.06 22:57 
Hi
Ich bin noch totaler PHP-Noob und komm schon nicht weiter. :wink:
Also ich lad eine html Datei in ein Array.
ausblenden Quelltext
1:
$html = file('http://www.google.de');					


Dann will ich rausfinden welche Zeile aus dem String "<script>" besteht.
ausblenden Quelltext
1:
$i = array_search('<script>', $html);					


Aber er gibt immer false zurück obwohl die Zeile vorkommt. :?
Welche Funktion brauch ich den dafür?

Edit//
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
  $html = file('http://www.google.de');

  foreach ($html as $i => $line) {
    if ($html[$i] == '<script>') {
      echo $i;
      break ;
    }
  }

Funktioniert auch nicht.
matze.de
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 576

Win95, Win98 SE, WinXp Prof SP2
D7P, D8P, FPC2.0
BeitragVerfasst: Fr 14.04.06 08:37 
Ist doch in der PHP-Hilfe schon gut erklärt wie man alle Zeilen durchgeht:
ausblenden Quelltext
1:
2:
3:
4:
5:
$lines = file ('http://www.google.de/');

foreach ($lines as $line_num => $line) {
   echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n";
}


mfg matze

//Edit: Hab dir ma ne Lösung gemacht:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
<?php
$wrapper = ini_get('allow_url_fopen');
echo "FOpen-Wrapper: ".($wrapper == 1 ? "<span style=\"color: green;\">An</span>" : "<span style=\"color: red;\">Aus</span>" ).".\n";

if ( (($lines = file ('http://www.google.de/')) === false) || ($wrapper != 1))
{
  echo "Fehler!\n";
  exit;
}

foreach ($lines as $line_num => $line) {
   if ( strpos(htmlspecialchars($line), htmlspecialchars('<script>')) !== false )
     echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "\n";
}
?>

_________________
si tacuisses, philosophus mansisses.
Coder Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1383
Erhaltene Danke: 1

WinXP
D2005 PE
BeitragVerfasst: Fr 14.04.06 18:06 
Danke das hat mir sehr geholfen! :D

Eine Frage hab ich noch.
Wieso kann man den String nicht auch so vergleichen?
ausblenden Quelltext
1:
if ($line == '<h3>Beschreibung</h3>') {...}					
matze.de
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 576

Win95, Win98 SE, WinXp Prof SP2
D7P, D8P, FPC2.0
BeitragVerfasst: Fr 14.04.06 19:18 
user profile iconCoder hat folgendes geschrieben:
Danke das hat mir sehr geholfen! :D

Eine Frage hab ich noch.
Wieso kann man den String nicht auch so vergleichen?
ausblenden Quelltext
1:
if ($line == '<h3>Beschreibung</h3>') {...}					


Was is wenn $line vom Inhalt so aussieht: "<h3>Beschreibung</h3> " Dann findet er es nicht nur weil ein Leerzeichen dahinter steht und das wäre ja blöd :)

mfg matze

_________________
si tacuisses, philosophus mansisses.
Coder Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1383
Erhaltene Danke: 1

WinXP
D2005 PE
BeitragVerfasst: Fr 14.04.06 21:48 
Aha :D
Trotzdem ists etwas komisch da in den Zeilen genau das gleiche steht.
DarkHunter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 477

Win XP
D3 Prof, D2005 PE
BeitragVerfasst: Fr 14.04.06 22:18 
Am einfachsten nimmst du statt file() - file_get_contents() dann hast du das alles in einem String ;)

als nächstes suchst du dann mit preg_match_all() nachdem String, fertig ;)

ausblenden Quelltext
1:
2:
3:
$file_content = file_get_contents('foo.bar') ;
//$str ist der String nach dem du suchst
preg_match_all($str,$file_content,$results);


damit du weißt was in $results alles drinne steht, schaust du dir am besten mal die funktion preg_match_all in der PHP-Doku an

_________________
I believe that every human has a finite number of heart-beats. I don't intend to waste any of mine running around doing exercises.
- Neil Armstrong