TXT - Nur bestimmte Zeilen in array

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Ich würde einfach die Datei mittels file() einlesen, jedes Element mittels einer String Fkt prüfen und im Erfolgsfall die Zeile in ein Ausgabe Array exploden
    PHP Code:
    $temp file('deine.txt');
    $ausgabe = array();
    foreach(
    $temp as $wert){
        if(
    strpos(trim($wert),'all') !== false){
            
    $ausgabe[] = explode('|',trim($wert));
        }

    Ein count($ausgabe) sollte dir dann die Anzahl Elemente geben, auf die die Bedingung zutrifft.

    Gruss

    tobi
    Gutes Tutorial | PHP Manual | MySql Manual | PHP FAQ | Apache | Suchfunktion für eigene Seiten

    [color=red]"An error does not become truth by reason of multiplied propagation, nor does truth become error because nobody sees it."[/color]
    Mohandas Karamchand Gandhi (Mahatma Gandhi) (Source)

    Comment


    • #17
      Das Problem mit strpos() dürfte aber sein, dass Kategorien, die nicht zur Kategorie "all" gehören, jedoch die Zeichenfolge "all" beinhalten, fälschlicherweise gematcht werden, oder nicht?
      Nieder mit der Camel Case-Konvention

      Comment


      • #18
        Das Problem mit strpos() dürfte aber sein, dass Kategorien, die nicht zur Kategorie "all" gehören, jedoch die Zeichenfolge "all" beinhalten, fälschlicherweise gematcht werden, oder nicht?
        Das stimmt. Habe ich gar nicht daran gedacht
        PHP Code:
        $temp file('deine.txt');
        $ausgabe = array();
        foreach(
        $temp as $wert){
            if(
        strpos(trim($wert),'all') !== false){
                
        $t explode('|',trim($wert));
                if(
        $t[5] == 'all'){
                    
        $ausgabe[] = $t;
                }
            }

        Das wäre jetzt so mein Vorschlag

        Gruss

        tobi
        Gutes Tutorial | PHP Manual | MySql Manual | PHP FAQ | Apache | Suchfunktion für eigene Seiten

        [color=red]"An error does not become truth by reason of multiplied propagation, nor does truth become error because nobody sees it."[/color]
        Mohandas Karamchand Gandhi (Mahatma Gandhi) (Source)

        Comment

        Working...
        X