explode

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Davide

    #1

    explode

    Hi All, I'm trying to use explode to separate the result of a textual
    file, but it explode me only the first row.

    the foo.txt is
    pippo pluto
    pluto pippo
    pippo pippo
    ....

    I use this script found in http://it2.php.net/manual/en/function.explode.php

    $pizza = "/var/www/foo.txt";
    $pieces = explode(" ", $pizza);
    echo $pieces[0]; // piece1
    echo $pieces[1]; // piece2

  • Davide

    #2
    Re: explode

    sorry.. this is the correct one:

    $pizza = "/var/www/foo.txt";
    $lines = file('/var/www/foo.txt');
    foreach ($lines as $line_num =$line) {
    htmlspecialchar s($line) . "<br />\n";
    $pieces = explode(" ", htmlspecialchar s($line) . "<br />\n");
    echo $pieces[0]; // piece1
    echo $pieces[1]; // piece2
    }

    it echoes only the first line of the file

    pippo pluto

    Comment

    • Davide

      #3
      Re: explode

      On 24 Mar, 09:39, "Davide" <davide.papa... @gmail.comwrote :
      sorry.. this is the correct one:
      >
      $pizza = "/var/www/foo.txt";
      $lines = file('/var/www/foo.txt');
      foreach ($lines as $line_num =$line) {
      htmlspecialchar s($line) . "<br />\n";
      $pieces = explode(" ", htmlspecialchar s($line) . "<br />\n");
      echo $pieces[0]; // piece1
      echo $pieces[1]; // piece2
      }
      >
      it echoes only the first line of the file
      >
      pippo pluto
      Ok.. I solved...
      It was the space in <br />

      $pizza = "/var/www/foo.txt";
      $lines = file('/var/www/foo.txt');
      foreach ($lines as $line_num =$line) {
      htmlspecialchar s($line) . "<br>\n";
      $pieces = explode(" ", htmlspecialchar s($line) . "<br>\n");
      echo $pieces[0]; // piece1
      echo $pieces[1]; // piece2
      }

      Comment

      • Erwin Moller

        #4
        Re: explode

        Davide wrote:
        On 24 Mar, 09:39, "Davide" <davide.papa... @gmail.comwrote :
        >sorry.. this is the correct one:
        >>
        >$pizza = "/var/www/foo.txt";
        >$lines = file('/var/www/foo.txt');
        >foreach ($lines as $line_num =$line) {
        > htmlspecialchar s($line) . "<br />\n";
        > $pieces = explode(" ", htmlspecialchar s($line) . "<br />\n");
        > echo $pieces[0]; // piece1
        > echo $pieces[1]; // piece2
        > }
        >>
        >it echoes only the first line of the file
        >>
        > pippo pluto
        >
        Ok.. I solved...
        It was the space in <br />
        >
        $pizza = "/var/www/foo.txt";
        $lines = file('/var/www/foo.txt');
        foreach ($lines as $line_num =$line) {
        htmlspecialchar s($line) . "<br>\n";
        $pieces = explode(" ", htmlspecialchar s($line) . "<br>\n");
        echo $pieces[0]; // piece1
        echo $pieces[1]; // piece2
        }
        Well, you seemed to solved it all by yourself. :-)
        Now have a nice pizza. :P

        Regards,
        Erwin Moller

        Comment

        • PigInACage

          #5
          Re: explode

          On 26 Mar, 14:05, Erwin Moller
          <since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
          Davide wrote:
          On 24 Mar, 09:39, "Davide" <davide.papa... @gmail.comwrote :
          sorry.. this is the correct one:
          >
          $pizza = "/var/www/foo.txt";
          $lines = file('/var/www/foo.txt');
          foreach ($lines as $line_num =$line) {
          htmlspecialchar s($line) . "<br />\n";
          $pieces = explode(" ", htmlspecialchar s($line) . "<br />\n");
          echo $pieces[0]; // piece1
          echo $pieces[1]; // piece2
          }
          >
          it echoes only the first line of the file
          >
          pippo pluto
          >
          Ok.. I solved...
          It was the space in <br />
          >
          $pizza = "/var/www/foo.txt";
          $lines = file('/var/www/foo.txt');
          foreach ($lines as $line_num =$line) {
          htmlspecialchar s($line) . "<br>\n";
          $pieces = explode(" ", htmlspecialchar s($line) . "<br>\n");
          echo $pieces[0]; // piece1
          echo $pieces[1]; // piece2
          }
          >
          Well, you seemed to solved it all by yourself. :-)
          Now have a nice pizza. :P
          >
          Regards,
          Erwin Moller
          Yes! Just RTFM carefully :)
          Hope it helps someone...
          :P

          Comment

          Working...