Use PHP to convert a text file to an array

I have a text file here that I need to be able to convert to strings to extract the second, third, fourth and fifth values ​​from.

The first 7 values ​​of each line are limited to tabs, then there is a new line, then the last three values ​​are limited to tabs.

I removed the line break for a new line so that each line is completely tabbed.

<?php

$file="140724.txt";

$fopen = fopen($file, "r");

$fread = fread($fopen,filesize("$file"));

fclose($fopen);

$remove = "\n";

split = explode($remove, $fread);

foreach ($split as $string)
{
echo "$string<br><br>";
}

?>

What produces it .

, . PHP, , , , . , , , , .

+4
3

:

<?php
    $file="140724.txt";

    $fopen = fopen($file, r);

    $fread = fread($fopen,filesize($file));

    fclose($fopen);

    $remove = "\n";

    $split = explode($remove, $fread);

    $array[] = null;
    $tab = "\t";

    foreach ($split as $string)
    {
        $row = explode($tab, $string);
        array_push($array,$row);
    }
    echo "<pre>";
    print_r($array);
    echo "</pre>";
?>

:

enter image description here

1- .

+7

, . use fgetcsv() . . PHP.

+1
<?php
$myfile = fopen("test.txt", "r") or die("Unable to open file!");
// Output one line until end-of-file
while(!feof($myfile)) {
    $text[] = fgets($myfile);
}
fclose($myfile);
print_r($text);
?>
0

All Articles