split file into an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
bluesman333
Forum Commoner
Posts: 52
Joined: Wed Dec 31, 2003 9:47 am

split file into an array

Post 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;
?>
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post 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;
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Post Reply