Page 1 of 1

split file into an array

Posted: Sat Mar 05, 2005 3:07 pm
by bluesman333

Code: Select all

<?php
i've got a .txt file that contains values in a row separated by tabs
and columns seaparated by 3 tabs

i'm trying to split them the values into an array at the tabs

i think i'm way off here.  can someone point me in the right direction.


if (isset($_FILES&#1111;'report'])) &#123;

$file_to_be_processed = $_FILES&#1111;'report']&#1111;'tmp_name'];


$file = file($file_to_be_processed);
$line_array = split("\t | \t\t\t", $file);

foreach($line_array as $val) &#123;
	print "$val<br>";
	&#125;
?>

Posted: Sat Mar 05, 2005 3:14 pm
by Todd_Z

Code: Select all

if ( file_exists($_GET&#1111;"file"]) ) &#123;
 
    $fileContents = file_get_contents($_GET&#1111;"file"]);

    $lines = explode( "\n", $fileContents );

    foreach ( $lines as $line ) &#123;
      $info = explode( "\t\t\t", $line );
      foreach ( $info as $piece )
        echo "<br>$piece";
    &#125;

  &#125; else &#123;
    echo "File doesn't exist.";
  &#125;

Posted: Sat Mar 05, 2005 4:36 pm
by timvw