Accessing CSV File for PHP Parsing from Remote Server

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • PulsarSL@gmail.com

    Accessing CSV File for PHP Parsing from Remote Server

    Hey everyone,

    What function can I use to grab a .csv file from a remote webserver for
    use in my PHP script. I want to do some parsing and statistical
    analysis on it (server side).

    What PHP function is used for this? I can't seem to find it in Google
    or the online PHP manual, because I don't really know what keywords to
    use.

    Thank you very much

    PulsarSL

  • NC

    #2
    Re: Accessing CSV File for PHP Parsing from Remote Server

    PulsarSL@gmail. com wrote:[color=blue]
    >
    > What function can I use to grab a .csv file from a remote webserver for
    > use in my PHP script. I want to do some parsing and statistical
    > analysis on it (server side).[/color]

    Depends on how you want the remote data. Either file() or
    file_get_conten ts() should do the trick. See documentation for more
    details:




    Cheers,
    NC

    Comment

    • Mustafa Yalcin Acikyildiz

      #3
      Re: Accessing CSV File for PHP Parsing from Remote Server

      <?php
      /* cvsParser.php Parse CSV file(s)
      Copyright (C) 2005 Mustafa Y. Acikyildiz <yalcin at webliyacelebi dot
      com>

      This program is free software; you can redistribute it and/or modify it
      under the terms of the GNU General Public License as published by the
      Free
      Software Foundation; either version 2 of the License, or (at your
      option)
      any later version.

      This program is distributed in the hope that it will be useful, but
      WITHOUT
      ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      FITNESS
      FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
      details.

      You should have received a copy of the GNU General Public License along
      with
      this library; if not, write to the Free Software Foundation, Inc., 59
      Temple
      Place, Suite 330, Boston, MA 02111-1307 USA
      */

      $remoteFileAddr = "http://10.0.0.99/x.csv";
      $content = file_get_conten ts($remoteFileA ddr) or die ("error");
      $seperator = ";";

      $nPos = strpos($content ,"\n");
      $firstLine = substr($content , 0, $nPos);
      // subtracting first line(column titles) from main content
      $content = substr($content , $nPos, strlen($content ));
      $colNum = substr_count($f irstLine, $seperator);

      // Exploding First Line for Column titles
      $tree = explode($sepera tor, $firstLine);

      // Parsing Data
      // Exploding content line by line
      $lbl = explode("\n", $content);

      $conCount = count($lbl);

      foreach ($tree as $title) {
      echo "$title \t";
      }
      echo "\n";
      foreach ($lbl as $line) {
      $i = 0;
      // Exploding content with seperator
      $cols = explode($sepera tor, $line);
      foreach ($cols as $col) {
      echo "$col \t";
      $i++;
      }
      echo "\n";
      }
      ?>

      Comment

      • Mustafa Yalcin Acikyildiz

        #4
        Re: Accessing CSV File for PHP Parsing from Remote Server

        <?php
        /* csvParser.php Parse CSV file(s)
        Copyright (C) 2005 Mustafa Y. Acikyildiz <yalcin at webliyacelebi dot
        com>

        This program is free software; you can redistribute it and/or modify it
        under the terms of the GNU General Public License as published by the
        Free
        Software Foundation; either version 2 of the License, or (at your
        option)
        any later version.

        This program is distributed in the hope that it will be useful, but
        WITHOUT
        ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
        FITNESS
        FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
        details.

        You should have received a copy of the GNU General Public License along
        with
        this library; if not, write to the Free Software Foundation, Inc., 59
        Temple
        Place, Suite 330, Boston, MA 02111-1307 USA
        */
        $remoteFileAddr = "http://10.0.0.99/x.csv";
        $content = file_get_conten ts($remoteFileA ddr) or die ("error");
        $seperator = ";";

        $nPos = strpos($content ,"\n");
        $firstLine = substr($content , 0, $nPos);
        // subtracting first line(column titles) from main content
        $content = substr($content , $nPos, strlen($content ));
        $colNum = substr_count($f irstLine, $seperator);

        // Exploding First Line for Column titles
        $tree = explode($sepera tor, $firstLine);

        // Parsing Data
        // Exploding content line by line
        $lbl = explode("\n", $content);

        $conCount = count($lbl);

        foreach ($tree as $title) {
        echo "$title \t";
        }
        echo "\n";
        foreach ($lbl as $line) {
        $i = 0;
        // Exploding content with seperator
        $cols = explode($sepera tor, $line);
        foreach ($cols as $col) {
        echo "$col \t";
        $i++;
        }
        echo "\n";
        }
        ?>

        Comment

        • Andy Hassall

          #5
          Re: Accessing CSV File for PHP Parsing from Remote Server

          On 15 Dec 2005 15:26:37 -0800, PulsarSL@gmail. com wrote:
          [color=blue]
          >What function can I use to grab a .csv file from a remote webserver for
          >use in my PHP script. I want to do some parsing and statistical
          >analysis on it (server side).
          >
          >What PHP function is used for this? I can't seem to find it in Google
          >or the online PHP manual, because I don't really know what keywords to
          >use.[/color]

          Gets line from file pointer and parse for CSV fields

          --
          Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
          http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

          Comment

          • PulsarSL@gmail.com

            #6
            Re: Accessing CSV File for PHP Parsing from Remote Server

            Thanks everyone!

            PulsarSL

            Comment

            Working...